Module: LoyalSpider::EntityListerAble::InstanceMethods
- Defined in:
- lib/loyal_spider/ables/entity_lister_able.rb
Instance Method Summary collapse
- #_after_fetch_success(result) ⇒ Object
- #_before_fetch(options = {}) ⇒ Object
- #add_entity(entity) ⇒ Object
- #current_page ⇒ Object
- #entities ⇒ Object
-
#entity_clazz ⇒ Object
TODO.
- #fetch_url ⇒ Object
- #first_page? ⇒ Boolean
- #new_entity(attrs = {}) ⇒ Object
- #paged_fetch(page, options = {}, &block) ⇒ Object
- #url_format ⇒ Object
- #url_format_first ⇒ Object
- #url_format_options ⇒ Object
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 ={} @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_page ⇒ Object
95 96 97 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 95 def current_page @current_page ||= 1 end |
#entities ⇒ Object
76 77 78 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 76 def entities @entities ||= [] end |
#entity_clazz ⇒ Object
TODO
81 82 83 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 81 def entity_clazz self.class.[:entity_clazz] end |
#fetch_url ⇒ Object
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. || {} ).merge( :page => self.current_page ) ) end |
#first_page? ⇒ 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, ={}, &block self..merge!( [:url_format_options] || {} ) self.current_page = page self.fetch , &block end |
#url_format ⇒ Object
56 57 58 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 56 def url_format @url_format ||= self.class.[:url_format] end |
#url_format_first ⇒ Object
60 61 62 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 60 def url_format_first @url_format_first ||= self.class.[:url_format_first] end |
#url_format_options ⇒ Object
64 65 66 |
# File 'lib/loyal_spider/ables/entity_lister_able.rb', line 64 def @url_format_options ||= (self.class.[:url_format_options] || {}) end |