Class: Occi::Core::Categories
- Inherits:
-
Set
- Object
- Set
- Occi::Core::Categories
- Defined in:
- lib/occi/core/categories.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
- #<<(category) ⇒ Object
-
#as_json(options = {}) ⇒ Hashie::Mash
Json representation.
- #convert(category) ⇒ Object private
-
#get_related_to(category) ⇒ Occi::Core::Categories
Returns a Set with all categories related to the specified category.
-
#initialize(categories = []) ⇒ Categories
constructor
A new instance of Categories.
-
#inspect ⇒ String
Json representation.
- #join(separator) ⇒ Object
Constructor Details
#initialize(categories = []) ⇒ Categories
Returns a new instance of Categories.
7 8 9 10 |
# File 'lib/occi/core/categories.rb', line 7 def initialize(categories=[]) categories.collect! { |category| convert category } if categories super categories end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
5 6 7 |
# File 'lib/occi/core/categories.rb', line 5 def model @model end |
Instance Method Details
#<<(category) ⇒ Object
12 13 14 |
# File 'lib/occi/core/categories.rb', line 12 def <<(category) super convert category end |
#as_json(options = {}) ⇒ Hashie::Mash
Returns json representation.
37 38 39 |
# File 'lib/occi/core/categories.rb', line 37 def as_json(={}) self.to_a.as_json end |
#convert(category) ⇒ Object (private)
48 49 50 |
# File 'lib/occi/core/categories.rb', line 48 def convert(category) (@model.get_by_id category if @model if category.kind_of? String) or category end |
#get_related_to(category) ⇒ Occi::Core::Categories
Returns a Set with all categories related to the specified category
24 25 26 |
# File 'lib/occi/core/categories.rb', line 24 def (category) self.class.new select { |cat| cat. category } end |
#inspect ⇒ String
Returns json representation.
42 43 44 |
# File 'lib/occi/core/categories.rb', line 42 def inspect JSON.pretty_generate(JSON.parse(to_json)) end |
#join(separator) ⇒ Object
16 17 18 |
# File 'lib/occi/core/categories.rb', line 16 def join(separator) self.to_a.join(separator) end |