Class: Imgwire::Pagination::Metadata

Inherits:
Struct
  • Object
show all
Defined in:
lib/imgwire/pagination.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#limitObject

Returns the value of attribute limit

Returns:

  • (Object)

    the current value of limit



7
8
9
# File 'lib/imgwire/pagination.rb', line 7

def limit
  @limit
end

#next_pageObject

Returns the value of attribute next_page

Returns:

  • (Object)

    the current value of next_page



7
8
9
# File 'lib/imgwire/pagination.rb', line 7

def next_page
  @next_page
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page



7
8
9
# File 'lib/imgwire/pagination.rb', line 7

def page
  @page
end

#prev_pageObject

Returns the value of attribute prev_page

Returns:

  • (Object)

    the current value of prev_page



7
8
9
# File 'lib/imgwire/pagination.rb', line 7

def prev_page
  @prev_page
end

#total_countObject

Returns the value of attribute total_count

Returns:

  • (Object)

    the current value of 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