Class: YahooShoppingSearch::Responses::Base
- Inherits:
-
Object
- Object
- YahooShoppingSearch::Responses::Base
- Includes:
- Enumerable
- Defined in:
- lib/yahoo_shopping_search/responses/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #[](index) ⇒ YahooShoppingSearch::Resources::Base | nil
- #body ⇒ Hash
- #each(&block) ⇒ Object
-
#initialize(body, params = {}) ⇒ Base
constructor
A new instance of Base.
- #items ⇒ Array<YahooShoppingSearch::Resources::Base>
- #last ⇒ YahooShoppingSearch::Resources::Base | nil
- #params ⇒ Hash
-
#resource_class ⇒ Object
Specify class name.
-
#sources ⇒ Object
Specify class name.
Constructor Details
#initialize(body, params = {}) ⇒ Base
Returns a new instance of Base.
10 11 12 13 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 10 def initialize(body, params = {}) @body = JSON.parse(body) @params = params end |
Instance Method Details
#[](index) ⇒ YahooShoppingSearch::Resources::Base | nil
49 50 51 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 49 def [](index) items[index] end |
#body ⇒ Hash
16 17 18 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 16 def body @body end |
#each(&block) ⇒ Object
Note:
Implementation for Enumerable
26 27 28 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 26 def each(&block) items.each(&block) end |
#items ⇒ Array<YahooShoppingSearch::Resources::Base>
31 32 33 34 35 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 31 def items (sources || []).map do |source| resource_class.new(source) end end |
#last ⇒ YahooShoppingSearch::Resources::Base | nil
54 55 56 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 54 def last items.last end |
#params ⇒ Hash
21 22 23 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 21 def params @params end |
#resource_class ⇒ Object
Specify class name
43 44 45 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 43 def resource_class raise NotImplementedError end |
#sources ⇒ Object
Specify class name
38 39 40 |
# File 'lib/yahoo_shopping_search/responses/base.rb', line 38 def sources raise NotImplementedError end |