Class: ElectionBuddy::Validation::LineErrors
- Inherits:
-
Object
- Object
- ElectionBuddy::Validation::LineErrors
- Includes:
- Enumerable
- Defined in:
- lib/election_buddy/entities/validation/line_errors.rb
Overview
Represents a collection of line-by-line validation errors
Instance Attribute Summary collapse
-
#page ⇒ Integer
readonly
Current page number.
-
#per_page ⇒ Integer
readonly
Number of items per page.
-
#total ⇒ Integer
readonly
Total number of validation errors.
Instance Method Summary collapse
- #collection ⇒ Object private
-
#each(&block) ⇒ Enumerator
Iterates through each line error.
-
#empty? ⇒ Boolean
Checks if there are any line errors.
-
#initialize(response) ⇒ LineErrors
constructor
A new instance of LineErrors.
-
#total_pages ⇒ Integer
Calculates the total number of pages.
Constructor Details
#initialize(response) ⇒ LineErrors
Returns a new instance of LineErrors.
26 27 28 29 30 31 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 26 def initialize(response) @line_errors = response["voter_line_errors"] @total = response["meta"]["total"] @page = response["meta"]["page"] @per_page = response["meta"]["per_page"] end |
Instance Attribute Details
#page ⇒ Integer (readonly)
Returns Current page number.
20 21 22 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 20 def page @page end |
#per_page ⇒ Integer (readonly)
Returns Number of items per page.
23 24 25 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 23 def per_page @per_page end |
#total ⇒ Integer (readonly)
Returns Total number of validation errors.
17 18 19 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 17 def total @total end |
Instance Method Details
#collection ⇒ Object (private)
56 57 58 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 56 def collection @collection ||= @line_errors.map { |line_error| LineError.new(line_error) } end |
#each(&block) ⇒ Enumerator
Iterates through each line error
43 44 45 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 43 def each(&block) collection.each(&block) end |
#empty? ⇒ Boolean
Checks if there are any line errors
50 51 52 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 50 def empty? collection.empty? end |
#total_pages ⇒ Integer
Calculates the total number of pages
36 37 38 |
# File 'lib/election_buddy/entities/validation/line_errors.rb', line 36 def total_pages (total.to_f / per_page).ceil end |