Class: RubyHome::CharacteristicTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_home/factories/templates/characteristic_template.rb

Constant Summary collapse

FILEPATH =
(File.dirname(__FILE__) + '/../../config/characteristics.yml').freeze
DATA =
YAML.load_file(FILEPATH).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, uuid:, format:, unit:, permissions:, properties:, constraints:) ⇒ CharacteristicTemplate

Returns a new instance of CharacteristicTemplate.



18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 18

def initialize(name:, description:, uuid:, format:, unit:, permissions:, properties:, constraints:)
  @name = name
  @description = description
  @uuid = uuid
  @format = format
  @unit = unit
  @permissions = permissions
  @properties = properties
  @constraints = constraints
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def description
  @description
end

#formatObject (readonly)

Returns the value of attribute format.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def format
  @format
end

#nameObject (readonly)

Returns the value of attribute name.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def name
  @name
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def permissions
  @permissions
end

#propertiesObject (readonly)

Returns the value of attribute properties.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def properties
  @properties
end

#unitObject (readonly)

Returns the value of attribute unit.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def unit
  @unit
end

#uuidObject (readonly)

Returns the value of attribute uuid.



29
30
31
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 29

def uuid
  @uuid
end

Class Method Details

.allObject



6
7
8
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 6

def self.all
  @@all ||= DATA.map { |data| new(data) }
end

.find_by(options) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 10

def self.find_by(options)
  all.find do |characteristic|
    options.all? do |key, value|
      characteristic.send(key) == value
    end
  end
end

Instance Method Details

#to_hashObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 31

def to_hash
  {
    name: name,
    description: description,
    uuid: uuid,
    format: format,
    unit: unit,
    properties: properties,
  }
end