Class: Wonde::ResultIterator
- Includes:
- Enumerable
- Defined in:
- lib/resultiterator.rb
Instance Attribute Summary collapse
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#myarray ⇒ Object
Returns the value of attribute myarray.
-
#token ⇒ Object
Returns the value of attribute token.
Attributes inherited from Endpoints
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #each ⇒ Object
-
#initialize(myhashostruct, token) ⇒ ResultIterator
constructor
A new instance of ResultIterator.
- #length ⇒ Object
Methods inherited from Endpoints
#all, #delete, #deleteRequest, #deleteUrl, #get, #getRequest, #getUrl, #post, #postRequest, #postUrl
Constructor Details
#initialize(myhashostruct, token) ⇒ ResultIterator
Returns a new instance of ResultIterator.
5 6 7 8 9 10 11 |
# File 'lib/resultiterator.rb', line 5 def initialize(myhashostruct, token) super p myhashostruct if ENV["debug_wonde"] self.token = token self.myarray = myhashostruct.data self. = myhashostruct. unless myhashostruct..nil? end |
Instance Attribute Details
#meta ⇒ Object
Returns the value of attribute meta.
4 5 6 |
# File 'lib/resultiterator.rb', line 4 def @meta end |
#myarray ⇒ Object
Returns the value of attribute myarray.
4 5 6 |
# File 'lib/resultiterator.rb', line 4 def myarray @myarray end |
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/resultiterator.rb', line 4 def token @token end |
Instance Method Details
#<<(val) ⇒ Object
13 14 15 |
# File 'lib/resultiterator.rb', line 13 def <<(val) @myarray << val end |
#each ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/resultiterator.rb', line 21 def each original_length = @myarray.length - 1 @myarray.each_with_index do |val,index| if index >= original_length and self. and self..pagination.more resp = self.getUrl(self..pagination.next).body nextResponse = JSON.parse(resp, object_class: OpenStruct) p nextResponse if ENV["debug_wonde"] self. = nextResponse. unless nextResponse..nil? nextResponse.data.each do |element| @myarray.push(element) end original_length += nextResponse.data.count end yield val end end |
#length ⇒ Object
17 18 19 |
# File 'lib/resultiterator.rb', line 17 def length return self.count() end |