Module: LoyalSpider::EntityListerAble::InstanceMethods

Defined in:
lib/loyal_spider/ables/entity_lister_able.rb

Instance Method Summary collapse

Instance Method Details

#_after_fetch_success(result) ⇒ Object



72
73
74
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 72

def _after_fetch_success result
  result.entities = self.entities
end

#_before_fetch(options = {}) ⇒ Object



68
69
70
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 68

def _before_fetch options={}
  @entities = []
end

#add_entity(entity) ⇒ Object



91
92
93
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 91

def add_entity entity
  self.entities << entity
end

#current_pageObject



95
96
97
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 95

def current_page
  @current_page ||= 1
end

#entitiesObject



76
77
78
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 76

def entities
  @entities ||= []
end

#entity_clazzObject

TODO



81
82
83
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 81

def entity_clazz
  self.class.entity_lister_options[:entity_clazz]
end

#fetch_urlObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 103

def fetch_url
  return @fetch_url if defined?(@fetch_url)

  _url_format = self.first_page? ? self.url_format_first : self.url_format

  @fetch_url ||= sprintf(
    _url_format, (
      self.url_format_options || {}
    ).merge(
      :page => self.current_page
    )
  )
end

#first_page?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 99

def first_page?
  self.current_page < 2
end

#new_entity(attrs = {}) ⇒ Object



85
86
87
88
89
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 85

def new_entity attrs={}
  if self.entity_clazz
    self.entity_clazz.new(attrs) 
  end
end

#paged_fetch(page, options = {}, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 46

def paged_fetch page, options={}, &block

  self.url_format_options.merge!(
    options[:url_format_options] || {}
  )

  self.current_page = page
  self.fetch options, &block
end

#url_formatObject



56
57
58
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 56

def url_format
  @url_format ||= self.class.entity_lister_options[:url_format]
end

#url_format_firstObject



60
61
62
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 60

def url_format_first
  @url_format_first ||= self.class.entity_lister_options[:url_format_first]
end

#url_format_optionsObject



64
65
66
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 64

def url_format_options
  @url_format_options ||= (self.class.entity_lister_options[:url_format_options] || {})
end