Class: InfluxDB::PointValue

Inherits:
Object
  • Object
show all
Defined in:
lib/influxdb/point_value.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ PointValue

Returns a new instance of PointValue.



8
9
10
# File 'lib/influxdb/point_value.rb', line 8

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/influxdb/point_value.rb', line 6

def value
  @value
end

Instance Method Details

#dumpObject



12
13
14
15
16
17
18
# File 'lib/influxdb/point_value.rb', line 12

def dump
  if value.is_a?(Array) || value.is_a?(Hash)
    JSON.generate(value)
  else
    value
  end
end

#loadObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/influxdb/point_value.rb', line 20

def load
  if maybe_json?
    begin
      JSON.parse(value)
    rescue JSON::ParserError => e
      value
    end
  else
    value
  end
end

#maybe_json?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/influxdb/point_value.rb', line 32

def maybe_json?
  value.is_a?(String) && value =~ /\A(\{|\[).*(\}|\])$/
end