Class: LeanTesting::EntityList
- Inherits:
-
Object
- Object
- LeanTesting::EntityList
- Defined in:
- lib/BaseClass/EntityList.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
-
#count ⇒ Object
Outputs number of Entities in current collection page.
-
#each ⇒ Object
Internal loop handler for emulating enumerable functionality.
-
#first ⇒ Object
Sets iterator position to first page.
-
#initialize(origin, request, identifier, filters = nil) ⇒ EntityList
constructor
Constructs an Entity List instance.
-
#last ⇒ Object
Sets iterator position to last page.
-
#next ⇒ Object
Sets iterator position to next page.
-
#previous ⇒ Object
Sets iterator position to previous page.
-
#toArray ⇒ Object
Outputs internal collection in array format (converted from Entity objects).
-
#total ⇒ Object
Outputs total number of Entities inside multi-page collection.
-
#totalPages ⇒ Object
Outputs total number of pages the multi-page collection has, regardful of limit/per_page.
Constructor Details
#initialize(origin, request, identifier, filters = nil) ⇒ EntityList
Constructs an Entity List instance.
Arguments: origin Client – Original client instance reference request APIRequest – An API Request definition given by the entity collection handler. This is used for any subsequent collection regeneration, as any data updates are dependant on external requests. identifier Class – class definition to use for dynamic class instancing within array collection filters Hash – original filters passed over from originating all() call
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/BaseClass/EntityList.rb', line 28 def initialize(origin, request, identifier, filters = nil) if !filters filters = {} end @origin = origin @request = request @identifier = identifier @filters = filters generateCollectionData end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
6 7 8 |
# File 'lib/BaseClass/EntityList.rb', line 6 def collection @collection end |
Instance Method Details
#count ⇒ Object
Outputs number of Entities in current collection page. Will always be same as limmit/per_page if not on last page.
Returns: Fixnum – Number of Entities in page
131 132 133 |
# File 'lib/BaseClass/EntityList.rb', line 131 def count @pagination['count'] end |
#each ⇒ Object
Internal loop handler for emulating enumerable functionality
98 99 100 101 102 103 |
# File 'lib/BaseClass/EntityList.rb', line 98 def each first begin yield toArray end while self.next end |
#first ⇒ Object
Sets iterator position to first page. Ignored if already on first page.
45 46 47 48 49 50 51 52 |
# File 'lib/BaseClass/EntityList.rb', line 45 def first if @pagination['current_page'] == 1 return false end @filters['page'] = 1 generateCollectionData end |
#last ⇒ Object
Sets iterator position to last page. Ignored if already on last page.
86 87 88 89 90 91 92 93 |
# File 'lib/BaseClass/EntityList.rb', line 86 def last if @pagination['current_page'] == @pagination['total_pages'] return false end @filters['page'] = @pagination['total_pages'] generateCollectionData end |
#next ⇒ Object
Sets iterator position to next page. Ignored if on last page.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/BaseClass/EntityList.rb', line 69 def next if @pagination['current_page'] == @pagination['total_pages'] return false end if @filters.has_key? 'page' @filters['page'] += 1 else @filters['page'] = 2 end generateCollectionData end |
#previous ⇒ Object
Sets iterator position to previous page. Ignored if on first page.
57 58 59 60 61 62 63 64 |
# File 'lib/BaseClass/EntityList.rb', line 57 def previous if @pagination['current_page'] == 1 return false end @filters['page'] -=1 generateCollectionData end |
#toArray ⇒ Object
Outputs internal collection in array format (converted from Entity objects)
Returns: Array – array of elements converted into hashes
141 142 143 |
# File 'lib/BaseClass/EntityList.rb', line 141 def toArray @collection.map{ |entity| entity.data } end |
#total ⇒ Object
Outputs total number of Entities inside multi-page collection
Returns: Fixnum – Number of total Entities
111 112 113 |
# File 'lib/BaseClass/EntityList.rb', line 111 def total @pagination['total'] end |
#totalPages ⇒ Object
Outputs total number of pages the multi-page collection has, regardful of limit/per_page
Returns: Fixnum – Number of total pages
121 122 123 |
# File 'lib/BaseClass/EntityList.rb', line 121 def totalPages @pagination['total_pages'] end |