Class: Funneler::Funnel
- Inherits:
-
Object
- Object
- Funneler::Funnel
- Defined in:
- lib/funneler/funnel.rb
Instance Attribute Summary collapse
-
#current_page_index ⇒ Object
readonly
Returns the value of attribute current_page_index.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page(additional_params = {}) ⇒ Object
-
#initialize(data = {}, current_page_index = nil) ⇒ Funnel
constructor
A new instance of Funnel.
- #is_last_page? ⇒ Boolean
- #meta ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(data = {}, current_page_index = nil) ⇒ Funnel
Returns a new instance of Funnel.
6 7 8 9 10 |
# File 'lib/funneler/funnel.rb', line 6 def initialize(data = {}, current_page_index = nil) @data = data @current_page_index = current_page_index || data.fetch("current_page_index", nil) || 0 @url_cache = Hash.new {|h, key| h[key] = generate_page_for_index(key) } end |
Instance Attribute Details
#current_page_index ⇒ Object (readonly)
Returns the value of attribute current_page_index.
4 5 6 |
# File 'lib/funneler/funnel.rb', line 4 def current_page_index @current_page_index end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/funneler/funnel.rb', line 4 def data @data end |
Instance Method Details
#current_page ⇒ Object
31 32 33 |
# File 'lib/funneler/funnel.rb', line 31 def current_page @url_cache[current_page_index] end |
#first_page(additional_params = {}) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/funneler/funnel.rb', line 12 def first_page(additional_params = {}) url = @url_cache[0] return url if additional_params.empty? add_params_to_url(url, additional_params) end |
#is_last_page? ⇒ Boolean
27 28 29 |
# File 'lib/funneler/funnel.rb', line 27 def is_last_page? routes.empty? || (current_page_index + 1) >= routes.length end |
#meta ⇒ Object
35 36 37 |
# File 'lib/funneler/funnel.rb', line 35 def data['meta'] || {} end |
#next_page ⇒ Object
19 20 21 |
# File 'lib/funneler/funnel.rb', line 19 def next_page @url_cache[next_index] end |
#previous_page ⇒ Object
23 24 25 |
# File 'lib/funneler/funnel.rb', line 23 def previous_page @url_cache[previous_index] end |
#token ⇒ Object
39 40 41 |
# File 'lib/funneler/funnel.rb', line 39 def token TokenHandler.generate_token(data: data) end |