Class: GunBroker::Category
- Inherits:
-
Object
- Object
- GunBroker::Category
- Defined in:
- lib/gun_broker/category.rb
Overview
Represents a GunBroker category.
Constant Summary collapse
- ROOT_CATEGORY_ID =
The top-level category ID.
0
Class Method Summary collapse
-
.all(parent_id = ROOT_CATEGORY_ID) ⇒ Array<Category>
An array of GunBroker::Category instances.
-
.find(category_id) ⇒ Category
A Category instance or
nil
if no Category withcategory_id
exists. -
.find!(category_id) ⇒ Category
Same as Category.find but raises GunBroker::Error::NotFound if no Category is found.
Instance Method Summary collapse
-
#[](key) ⇒ Object
The value of the given
key
ornil
. -
#id ⇒ Integer
The Category ID.
-
#initialize(attrs = {}) ⇒ Category
constructor
A new instance of Category.
-
#name ⇒ String
The Category name.
Constructor Details
#initialize(attrs = {}) ⇒ Category
Returns a new instance of Category.
32 33 34 |
# File 'lib/gun_broker/category.rb', line 32 def initialize(attrs = {}) @attrs = attrs end |
Class Method Details
.all(parent_id = ROOT_CATEGORY_ID) ⇒ Array<Category>
Returns An array of GunBroker::Category instances.
10 11 12 13 |
# File 'lib/gun_broker/category.rb', line 10 def self.all(parent_id = ROOT_CATEGORY_ID) response = GunBroker::API.get('/Categories', { 'ParentCategoryID' => parent_id, 'PageSize' => GunBroker::API::PAGE_SIZE }) response['results'].map { |attrs| new(attrs) } end |
Instance Method Details
#[](key) ⇒ Object
Returns The value of the given key
or nil
.
48 49 50 |
# File 'lib/gun_broker/category.rb', line 48 def [](key) @attrs[key] end |
#id ⇒ Integer
Returns The Category ID.
37 38 39 |
# File 'lib/gun_broker/category.rb', line 37 def id @attrs['categoryID'] end |
#name ⇒ String
Returns The Category name.
42 43 44 |
# File 'lib/gun_broker/category.rb', line 42 def name @attrs['categoryName'] end |