Class: RubyHome::CharacteristicTemplate

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

Constant Summary collapse

FILENAMES =
%w[characteristics.yml manual_characteristics.yml].freeze
FILEPATHS =
FILENAMES.map { |filename| File.join(__dir__, "..", "..", "config", filename) }.freeze
DATA =
FILEPATHS.flat_map { |filepath| 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:, properties:, constraints:) ⇒ CharacteristicTemplate

Returns a new instance of CharacteristicTemplate.



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

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

Instance Attribute Details

#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

#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



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

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

.find_by(options) ⇒ Object



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

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

Instance Method Details

#constraintsObject



31
32
33
# File 'lib/ruby_home/factories/templates/characteristic_template.rb', line 31

def constraints
  @constraints || {}
end