Class: Imgwire::Pagination::Metadata
- Inherits:
-
Struct
- Object
- Struct
- Imgwire::Pagination::Metadata
- Defined in:
- lib/imgwire/pagination.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#next_page ⇒ Object
Returns the value of attribute next_page.
-
#page ⇒ Object
Returns the value of attribute page.
-
#prev_page ⇒ Object
Returns the value of attribute prev_page.
-
#total_count ⇒ Object
Returns the value of attribute total_count.
Class Method Summary collapse
Instance Attribute Details
#limit ⇒ Object
Returns the value of attribute limit
7 8 9 |
# File 'lib/imgwire/pagination.rb', line 7 def limit @limit end |
#next_page ⇒ Object
Returns the value of attribute next_page
7 8 9 |
# File 'lib/imgwire/pagination.rb', line 7 def next_page @next_page end |
#page ⇒ Object
Returns the value of attribute page
7 8 9 |
# File 'lib/imgwire/pagination.rb', line 7 def page @page end |
#prev_page ⇒ Object
Returns the value of attribute prev_page
7 8 9 |
# File 'lib/imgwire/pagination.rb', line 7 def prev_page @prev_page end |
#total_count ⇒ Object
Returns the value of attribute total_count
7 8 9 |
# File 'lib/imgwire/pagination.rb', line 7 def total_count @total_count end |
Class Method Details
.from_headers(headers) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imgwire/pagination.rb', line 15 def self.from_headers(headers) normalized = {} headers.each do |key, value| normalized[key.to_s.downcase] = value end new( total_count: parse_int(normalized['x-total-count']), page: parse_int(normalized['x-page']), limit: parse_int(normalized['x-limit']), prev_page: parse_int(normalized['x-prev-page']), next_page: parse_int(normalized['x-next-page']) ) end |
.parse_int(value) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/imgwire/pagination.rb', line 30 def self.parse_int(value) return nil if value.nil? normalized = value.to_s.strip.downcase return nil if normalized.empty? || normalized == 'null' || normalized == 'none' normalized.to_i end |