Class: Funneler::Funnel

Inherits:
Object
  • Object
show all
Defined in:
lib/funneler/funnel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_indexObject (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

#dataObject (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_pageObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/funneler/funnel.rb', line 27

def is_last_page?
  routes.empty? || (current_page_index + 1) >= routes.length
end

#metaObject



35
36
37
# File 'lib/funneler/funnel.rb', line 35

def meta
  data['meta'] || {}
end

#next_pageObject



19
20
21
# File 'lib/funneler/funnel.rb', line 19

def next_page
  @url_cache[next_index]
end

#previous_pageObject



23
24
25
# File 'lib/funneler/funnel.rb', line 23

def previous_page
  @url_cache[previous_index]
end

#tokenObject



39
40
41
# File 'lib/funneler/funnel.rb', line 39

def token
  TokenHandler.generate_token(data: data)
end