Class: Taleo::Cursor
- Inherits:
-
Object
- Object
- Taleo::Cursor
- Defined in:
- lib/taleo/cursor.rb
Overview
Pages through results of a search query
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#pagination ⇒ Object
readonly
Returns the value of attribute pagination.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
- #has_next? ⇒ Boolean
- #has_previous? ⇒ Boolean
- #has_self? ⇒ Boolean
-
#initialize(pagination, results, resource, klass, client) ⇒ Cursor
constructor
A new instance of Cursor.
- #items ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #self_page ⇒ Object
Constructor Details
#initialize(pagination, results, resource, klass, client) ⇒ Cursor
Returns a new instance of Cursor.
8 9 10 11 12 13 14 |
# File 'lib/taleo/cursor.rb', line 8 def initialize(pagination, results, resource, klass, client) @pagination = pagination @results = results @resource = resource @klass = klass @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/taleo/cursor.rb', line 6 def client @client end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/taleo/cursor.rb', line 6 def klass @klass end |
#pagination ⇒ Object (readonly)
Returns the value of attribute pagination.
6 7 8 |
# File 'lib/taleo/cursor.rb', line 6 def pagination @pagination end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/taleo/cursor.rb', line 6 def resource @resource end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
6 7 8 |
# File 'lib/taleo/cursor.rb', line 6 def results @results end |
Instance Method Details
#has_next? ⇒ Boolean
22 23 24 |
# File 'lib/taleo/cursor.rb', line 22 def has_next? pagination.key?('next') end |
#has_previous? ⇒ Boolean
26 27 28 |
# File 'lib/taleo/cursor.rb', line 26 def has_previous? pagination.key?('previous') end |
#has_self? ⇒ Boolean
30 31 32 |
# File 'lib/taleo/cursor.rb', line 30 def has_self? pagination.key?('self') end |
#items ⇒ Object
16 17 18 19 20 |
# File 'lib/taleo/cursor.rb', line 16 def items results.map do |i| klass.new(i.fetch(resource), client) end end |
#next_page ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/taleo/cursor.rb', line 42 def next_page raise Taleo::Error.new('No further results') unless has_next? res = client.connection.get do |req| req.url pagination.fetch('next') end new_cursor(res) end |
#previous_page ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/taleo/cursor.rb', line 52 def previous_page raise Taleo::Error.new('No prior results') unless has_previous? res = client.connection.get do |req| req.url pagination.fetch('previous') end new_cursor(res) end |
#self_page ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/taleo/cursor.rb', line 34 def self_page res = client.connection.get do |req| req.url pagination.fetch('self') end new_cursor(res) end |