Class: Scalablepress::Category

Inherits:
Object
  • Object
show all
Defined in:
lib/scalablepress/resources/category.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Category

Returns a new instance of Category.



6
7
8
9
# File 'lib/scalablepress/resources/category.rb', line 6

def initialize(params)
  @name = params["name"]
  @category_id = params["categoryId"]
end

Instance Attribute Details

#category_idObject (readonly)

Returns the value of attribute category_id.



4
5
6
# File 'lib/scalablepress/resources/category.rb', line 4

def category_id
  @category_id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/scalablepress/resources/category.rb', line 3

def name
  @name
end

Class Method Details

.allObject



19
20
21
22
# File 'lib/scalablepress/resources/category.rb', line 19

def self.all
  result = API.get("categories")
  result.map { |params| Category.new(params) }
end

.find_by_id(id) ⇒ Object



15
16
17
# File 'lib/scalablepress/resources/category.rb', line 15

def self.find_by_id(id)
  all.select {|c| c.category_id == id }.first
end

Instance Method Details

#productsObject



11
12
13
# File 'lib/scalablepress/resources/category.rb', line 11

def products
  API.get("categories/#{@category_id}")["products"].map {|x| Product.new(x) }
end