Class: Occi::Core::AttributeProperties
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- Occi::Core::AttributeProperties
- Defined in:
- lib/occi/core/attribute_properties.rb
Class Method Summary collapse
-
.parse(properties) ⇒ Occi::Core::Attributes
Parsed Attribute Properties.
Instance Method Summary collapse
-
#initialize(properties = nil, default = nil) ⇒ AttributeProperties
constructor
A new instance of AttributeProperties.
-
#inspect ⇒ String
Json representation.
Constructor Details
#initialize(properties = nil, default = nil) ⇒ AttributeProperties
Returns a new instance of AttributeProperties.
9 10 11 12 13 14 15 16 |
# File 'lib/occi/core/attribute_properties.rb', line 9 def initialize(properties=nil,default=nil) properties ||= {} properties[:type] ||= 'string' properties[:required] ||= false properties[:mutable] ||= false properties[:pattern] ||= '.*' super properties, default end |
Class Method Details
.parse(properties) ⇒ Occi::Core::Attributes
Returns parsed Attribute Properties.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/occi/core/attribute_properties.rb', line 20 def self.parse(properties) properties ||= Hashie::Mash.new if [:Type, :Required, :Mutable, :Default, :Description, :Pattern, :type, :required, :mutable, :default, :description, :pattern].any? { |k| properties.key?(k) and not properties[k].kind_of? Hash } properties[:type] ||= properties[:Type] ||= "string" properties[:required] ||= properties[:Required] ||= false properties[:mutable] ||= properties[:Mutable] ||= false properties[:default] = properties[:Default] if properties[:Default] properties[:description] = properties[:Description] if properties[:Description] properties[:pattern] ||= properties[:Pattern] ||= ".*" properties.delete :Type properties.delete :Required properties.delete :Mutable properties.delete :Default properties.delete :Description properties.delete :Pattern return self.new properties else attributes = Occi::Core::Attributes.new properties.each_key do |key| attributes[key] = self.parse properties[key] end return attributes end end |
Instance Method Details
#inspect ⇒ String
Returns json representation.
46 47 48 |
# File 'lib/occi/core/attribute_properties.rb', line 46 def inspect JSON.pretty_generate(JSON.parse(to_json)) end |