Class: Storexplore::Walker

Inherits:
Object
  • Object
show all
Defined in:
lib/storexplore/walker.rb

Overview

Objects representing categories and items of the store. These are the instances manipulated when browsing a previously defined store

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(getter) ⇒ Walker

Returns a new instance of Walker.



30
31
32
33
34
35
# File 'lib/storexplore/walker.rb', line 30

def initialize(getter)
  self.categories_digger = NullDigger.new
  self.items_digger = NullDigger.new
  self.scrap_attributes_block = proc do { } end
  @getter = getter
end

Instance Attribute Details

#categories_diggerObject

Internal usage



28
29
30
# File 'lib/storexplore/walker.rb', line 28

def categories_digger
  @categories_digger
end

#fatherObject

Internal usage



28
29
30
# File 'lib/storexplore/walker.rb', line 28

def father
  @father
end

#indexObject

Internal usage



28
29
30
# File 'lib/storexplore/walker.rb', line 28

def index
  @index
end

#items_diggerObject

Internal usage



28
29
30
# File 'lib/storexplore/walker.rb', line 28

def items_digger
  @items_digger
end

#scrap_attributes_blockObject

Internal usage



28
29
30
# File 'lib/storexplore/walker.rb', line 28

def scrap_attributes_block
  @scrap_attributes_block
end

Instance Method Details

#attributesObject

Scraped attributes of this page. Attributes are extracted with the corresponding attributes blocks given in Storexplore::Dsl



51
52
53
# File 'lib/storexplore/walker.rb', line 51

def attributes
  @attributes ||= scrap_attributes
end

#categoriesObject

Sub categories Storexplore::Walker, as matched by the corresponding categories selector in Storexplore::Dsl



57
58
59
# File 'lib/storexplore/walker.rb', line 57

def categories
  categories_digger.sub_walkers(page, self)
end

#genealogyObject

Extended multiline string representation with parents.



73
74
75
# File 'lib/storexplore/walker.rb', line 73

def genealogy
  genealogy_prefix + to_s
end

#itemsObject

Sub items Storexplore::Walker, as matched by the corresponding categories selector in Storexplore::Dsl



63
64
65
# File 'lib/storexplore/walker.rb', line 63

def items
  items_digger.sub_walkers(page, self)
end

#titleObject

Early title, accessible before the page is loaded.

  • for the store root, this is the store uri

  • for other pages, it’s the caption of the link that brought to this



40
41
42
# File 'lib/storexplore/walker.rb', line 40

def title
  @getter.text
end

#to_sObject

String representation with uri and index among siblings.



68
69
70
# File 'lib/storexplore/walker.rb', line 68

def to_s
  "#{self.class} ##{index} @#{uri}"
end

#uriObject

Full uri of the page being browsed



45
46
47
# File 'lib/storexplore/walker.rb', line 45

def uri
  page.uri
end