Class: Svpply::Category
- Inherits:
-
Object
- Object
- Svpply::Category
- Defined in:
- lib/svpply/category.rb
Instance Attribute Summary collapse
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ Category
constructor
A new instance of Category.
- #products(attrs = nil) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Category
Returns a new instance of Category.
9 10 11 12 13 14 15 |
# File 'lib/svpply/category.rb', line 9 def initialize(hash) @name = hash["name"] @url = hash["url"] @children = hash["children"].nil? ? [] : hash["children"].map { |c| Category.new(c) } @api_url = @url[25, 1000] self end |
Instance Attribute Details
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
3 4 5 |
# File 'lib/svpply/category.rb', line 3 def api_url @api_url end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/svpply/category.rb', line 3 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/svpply/category.rb', line 3 def name @name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/svpply/category.rb', line 3 def url @url end |
Class Method Details
.all ⇒ Object
5 6 7 |
# File 'lib/svpply/category.rb', line 5 def self.all CategoryCollection.new(Client.get_response('/shop/categories.json')).categories end |
Instance Method Details
#products(attrs = nil) ⇒ Object
17 18 19 |
# File 'lib/svpply/category.rb', line 17 def products(attrs=nil) ProductCollection.new(Client.get_response(@api_url, attrs)).products end |