Module: Occi::Api::Client::Base::CategoryMethods

Included in:
ClientBase
Defined in:
lib/occi/api/client/base/category_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_category_type_identifier(type) ⇒ String?

Retrieves available category type identifier for the given category type.

Examples:

client.get_category_type_identifier("compute")
 # => 'http://schemas.ogf.org/occi/infrastructure#compute'

Parameters:

  • type (String)

    short category type

Returns:

  • (String, nil)

    category type identifier for the given category type


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/occi/api/client/base/category_methods.rb', line 37

def get_category_type_identifier(type)
  return type if (type =~ URI::ABS_URI) || (type && type.start_with?('/'))

  cats = @model.categories.to_a.select { |k| k.term == type }
  tis = cats.collect { |c| c.type_identifier }
  tis.uniq!

  if tis.length > 1
    raise Occi::Api::Client::Errors::AmbiguousNameError,
          "Category type #{type.inspect} is ambiguous, use a type identifier!"
  end

  tis.first
end

#get_category_type_identifiersArray<String>

Retrieves all available category type identifiers.

Examples:

client.get_category_type_identifiers
# => [ "http://schemas.ogf.org/occi/core#entity",
#      "http://schemas.ogf.org/occi/core#resource",
#      "http://schemas.ogf.org/occi/core#link" ]

Returns:

  • (Array<String>)

    list of available category type identifiers


25
26
27
# File 'lib/occi/api/client/base/category_methods.rb', line 25

def get_category_type_identifiers
  @model.categories.to_a.collect { |category| category.type_identifier }
end

#get_category_typesArray<String>

Retrieves all available category types.

Examples:

client.get_category_types # => [ "entity", "resource", "link" ]

Returns:

  • (Array<String>)

    list of available category types in a human-readable format


12
13
14
# File 'lib/occi/api/client/base/category_methods.rb', line 12

def get_category_types
  @model.categories.to_a.collect { |category| category.term }
end