Class: Occi::Core::Categories

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

Direct Known Subclasses

Actions, Kinds, Mixins, Related

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#modelObject

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.

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Hashie::Mash)

    json representation



37
38
39
# File 'lib/occi/core/categories.rb', line 37

def as_json(options={})
  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

Returns a Set with all categories related to the specified category

Parameters:

Returns:



24
25
26
# File 'lib/occi/core/categories.rb', line 24

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

#inspectString

Returns json representation.

Returns:

  • (String)

    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