Class: Occi::Core::Categories

Inherits:
Set
  • Object
show all
Includes:
Helpers::Inspect
Defined in:
lib/occi/core/categories.rb

Direct Known Subclasses

Actions, Kinds, Mixins, Related

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Inspect

#inspect

Constructor Details

#initialize(categories = []) ⇒ Categories


9
10
11
12
# File 'lib/occi/core/categories.rb', line 9

def initialize(categories=[])
  categories.collect! { |category| convert category } if categories
  super categories
end

Instance Attribute Details

#modelObject

Returns the value of attribute model


7
8
9
# File 'lib/occi/core/categories.rb', line 7

def model
  @model
end

Instance Method Details

#<<(category) ⇒ Object


14
15
16
# File 'lib/occi/core/categories.rb', line 14

def <<(category)
  super convert category
end

#as_json(options = {}) ⇒ Hashie::Mash


39
40
41
# File 'lib/occi/core/categories.rb', line 39

def as_json(options={})
  self.to_a.as_json
end

#convert(category) ⇒ Object (private)


45
46
47
# File 'lib/occi/core/categories.rb', line 45

def convert(category)
  (@model.get_by_id category if @model if category.kind_of? String) or category
end

Returns a Set with all categories related to the specified category


26
27
28
# File 'lib/occi/core/categories.rb', line 26

def get_related_to(category)
  self.class.new select { |cat| cat.related_to? category }
end

#join(separator) ⇒ Object


18
19
20
# File 'lib/occi/core/categories.rb', line 18

def join(separator)
  self.to_a.join(separator)
end