Class: ElectionBuddy::Importation

Inherits:
Object
  • Object
show all
Defined in:
lib/election_buddy/entities/importation.rb

Overview

Represents an importation operation for voter lists

Examples:

importation = Importation.new(response)
if importation.done?
  puts "Import successful: #{importation.identifier}"
else
  puts "Import failed: #{importation.error}"
end

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Importation

Returns a new instance of Importation.

Parameters:

  • response (Hash)

    The API response containing importation details



16
17
18
# File 'lib/election_buddy/entities/importation.rb', line 16

def initialize(response)
  @response = response
end

Instance Method Details

#done?Boolean

Checks if the importation completed successfully

Returns:

  • (Boolean)

    true if importation was successful, false otherwise



30
31
32
# File 'lib/election_buddy/entities/importation.rb', line 30

def done?
  @response["error"].nil?
end

#errorString?

Returns the error message if importation failed

Returns:

  • (String, nil)

    The formatted error message or nil if importation was successful



37
38
39
40
41
# File 'lib/election_buddy/entities/importation.rb', line 37

def error
  return nil if done?

  ErrorFormatter.format(@response["error"])
end

#identifierString

Returns the identifier for this importation

Returns:

  • (String)

    The importation identifier or "Not Available"



23
24
25
# File 'lib/election_buddy/entities/importation.rb', line 23

def identifier
  @response["importation_identifier"] || "Not Available"
end