Class: GovTrack::PaginatedList

Inherits:
Array
  • Object
show all
Defined in:
lib/govtrack/paginated_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_class, meta, objects) ⇒ PaginatedList

Returns a new instance of PaginatedList.



6
7
8
9
10
11
12
13
14
# File 'lib/govtrack/paginated_list.rb', line 6

def initialize(object_class,meta,objects)
  if meta
    @limit = meta['limit']
    @offset = meta['offset']
    @total = meta['total_count']
  end

  super((objects || []).map { |object| object_class.new(object) })
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *arguments) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/govtrack/paginated_list.rb', line 16

def method_missing(method_id, *arguments)
  #passes methods through to item when list contains only one
  if self.length == 1 
    self.first.send(method_id, *arguments)
  else
    super
  end
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



4
5
6
# File 'lib/govtrack/paginated_list.rb', line 4

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



4
5
6
# File 'lib/govtrack/paginated_list.rb', line 4

def offset
  @offset
end

#totalObject (readonly)

Returns the value of attribute total.



4
5
6
# File 'lib/govtrack/paginated_list.rb', line 4

def total
  @total
end