Module: HaystackRuby::Types::Number

Defined in:
lib/haystack_ruby/types/number.rb

Instance Method Summary collapse

Instance Method Details

#set_fields(str_value) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/haystack_ruby/types/number.rb', line 4

def set_fields str_value
  @haystack_type = 'Number'
  match = /\An:([-0-9E\-\.]*)( .*)*\z/.match str_value
  raise HaystackRuby::Error, "invalid HaystackRuby::Types::Number: #{str_value}" if match.nil?
  @value = match[1].to_f
  # also set unit if available
  @unit = match[2].strip if match[2].present?
end