Class: Chemtrail::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/chemtrail/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type, properties = nil) ⇒ Resource

Returns a new instance of Resource.



4
5
6
7
8
# File 'lib/chemtrail/resource.rb', line 4

def initialize(id, type, properties = nil)
  @id = id
  @type = type
  @properties = Chemtrail::PropertyList.new.merge(properties) if properties
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



2
3
4
# File 'lib/chemtrail/resource.rb', line 2

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



2
3
4
# File 'lib/chemtrail/resource.rb', line 2

def type
  @type
end

Instance Method Details

#propertiesObject



14
15
16
# File 'lib/chemtrail/resource.rb', line 14

def properties
  @properties ||= Chemtrail::PropertyList.new
end

#to_hashObject



18
19
20
21
22
23
24
25
# File 'lib/chemtrail/resource.rb', line 18

def to_hash
  {
    id => {
      "Type" => type,
      "Properties" => properties.to_hash
    }
  }
end

#to_referenceObject



10
11
12
# File 'lib/chemtrail/resource.rb', line 10

def to_reference
  { "Ref" => id }
end