Class: Thing

Inherits:
Object
  • Object
show all
Defined in:
lib/cisco-deviot/thing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, kind) ⇒ Thing

Returns a new instance of Thing.



93
94
95
96
97
98
99
# File 'lib/cisco-deviot/thing.rb', line 93

def initialize(id, name, kind)
  @id = id
  @name = name
  @kind = kind
  @properties = []
  @actions = []
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



91
92
93
# File 'lib/cisco-deviot/thing.rb', line 91

def actions
  @actions
end

#idObject (readonly)

Returns the value of attribute id.



87
88
89
# File 'lib/cisco-deviot/thing.rb', line 87

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



89
90
91
# File 'lib/cisco-deviot/thing.rb', line 89

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



88
89
90
# File 'lib/cisco-deviot/thing.rb', line 88

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



90
91
92
# File 'lib/cisco-deviot/thing.rb', line 90

def properties
  @properties
end

Instance Method Details

#add_action(action) ⇒ Object

Raises:

  • (ArgumentError)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cisco-deviot/thing.rb', line 113

def add_action(action)
  if action.instance_of? String
    @actions.push(Property.new(action))
    return self
  end
  if action.instance_of? Action
    @actions.push(action)
    return self
  end
  raise ArgumentError
end

#add_property(property) ⇒ Object

Raises:

  • (ArgumentError)


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cisco-deviot/thing.rb', line 101

def add_property(property)
  if property.instance_of? String
    @properties.push(Property.new(property))
    return self
  end
  if property.instance_of? Property
    @properties.push(property)
    return self
  end
  raise ArgumentError
end

#get_modelObject



129
130
131
132
# File 'lib/cisco-deviot/thing.rb', line 129

def get_model
  {id: @id, name: @name, kind: @kind, properties: @properties.collect {|p| p.get_model},
   actions: @actions.collect {|p| p.get_model}}
end

#to_sObject



125
126
127
# File 'lib/cisco-deviot/thing.rb', line 125

def to_s
  "#{@id}[#{@name}(#{@kind})]"
end