Class: Senec::Local::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/senec/local/value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Value

Returns a new instance of Value.



4
5
6
7
# File 'lib/senec/local/value.rb', line 4

def initialize(raw)
  @raw = raw
  @prefix, @value = raw&.split('_')
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



9
10
11
# File 'lib/senec/local/value.rb', line 9

def prefix
  @prefix
end

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/senec/local/value.rb', line 9

def raw
  @raw
end

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/senec/local/value.rb', line 9

def value
  @value
end

Instance Method Details

#decodedObject Also known as: to_i, to_f, to_s



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/senec/local/value.rb', line 11

def decoded
  case prefix
  when 'fl'
    decoded_float(value)
  when 'i3', 'u1', 'u3', 'u6', 'u8'
    decoded_int(value)
  when 'st'
    value
  # TODO: There are some more prefixes to handle
  else
    raise DecodingError, "Unknown value '#{@raw}'"
  end
end