Class: Property

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type = PROPERTY_TYPE_INT, value = nil, unit = '', range = nil, description = '') ⇒ Property

Returns a new instance of Property.



28
29
30
31
32
33
34
35
# File 'lib/cisco-deviot/thing.rb', line 28

def initialize(name, type = PROPERTY_TYPE_INT, value = nil, unit = '', range = nil, description = '')
  @name = name
  @type = type
  @value = value
  @unit = unit
  @range = range
  @description = description
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



26
27
28
# File 'lib/cisco-deviot/thing.rb', line 26

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/cisco-deviot/thing.rb', line 21

def name
  @name
end

#rangeObject (readonly)

Returns the value of attribute range.



25
26
27
# File 'lib/cisco-deviot/thing.rb', line 25

def range
  @range
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/cisco-deviot/thing.rb', line 22

def type
  @type
end

#unitObject (readonly)

Returns the value of attribute unit.



24
25
26
# File 'lib/cisco-deviot/thing.rb', line 24

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



23
24
25
# File 'lib/cisco-deviot/thing.rb', line 23

def value
  @value
end

Instance Method Details

#default_value_for(type) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cisco-deviot/thing.rb', line 37

def default_value_for(type)
  case type
    when PROPERTY_TYPE_INT
      return 0
    when PROPERTY_TYPE_STRING
      return ''
    when PROPERTY_TYPE_BOOL
      return FALSE
    when PROPERTY_TYPE_COLOR
      return 'FFFFFF'
    else
      return nil
  end
end

#get_modelObject



52
53
54
55
# File 'lib/cisco-deviot/thing.rb', line 52

def get_model
  {name: @name, type: @type, value: @value, range: @range,
   unit: @unit, description: @description}
end