Class: Smplkit::Config::ConfigItem

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/config/models.rb

Overview

A single typed item in a Config.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, type:, description: nil) ⇒ ConfigItem

Create a typed config item.

Parameters:

  • name (String)

    The item key within its config.

  • value (Object)

    The item’s value.

  • type (String)

    The item value type — one of “STRING”, “NUMBER”, “BOOLEAN”, or “JSON”.

  • description (String, nil) (defaults to: nil)

    Optional human-readable description.



26
27
28
29
30
31
# File 'lib/smplkit/config/models.rb', line 26

def initialize(name:, value:, type:, description: nil)
  @name = name
  @value = value
  @type = type
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



17
18
19
# File 'lib/smplkit/config/models.rb', line 17

def description
  @description
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/smplkit/config/models.rb', line 17

def name
  @name
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/smplkit/config/models.rb', line 17

def type
  @type
end

#valueObject

Returns the value of attribute value.



17
18
19
# File 'lib/smplkit/config/models.rb', line 17

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



39
40
41
42
# File 'lib/smplkit/config/models.rb', line 39

def ==(other)
  other.is_a?(ConfigItem) && other.name == @name && other.value == @value &&
    other.type == @type && other.description == @description
end

#hashObject



45
# File 'lib/smplkit/config/models.rb', line 45

def hash = [@name, @value, @type, @description].hash

#to_hHash{String => Object}

Returns The item as a plain Hash, omitting a nil description.

Returns:

  • (Hash{String => Object})

    The item as a plain Hash, omitting a nil description.



35
36
37
# File 'lib/smplkit/config/models.rb', line 35

def to_h
  { "name" => @name, "value" => @value, "type" => @type, "description" => @description }.compact
end