influxparser 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a35192cf489f487d8a42343384e1528d5168047
4
- data.tar.gz: fa965f4209d17c97bf4bde7508c5cc9fe07cfcd0
3
+ metadata.gz: f52776eebd46f588f036de0d523f3a8877c122e1
4
+ data.tar.gz: 9a798c8a95952675cb11961e52cd91a3e6b03d12
5
5
  SHA512:
6
- metadata.gz: 870efd15c7c9df408b15a2da2dc11134c6c2bd45ff69bdd213b30a3913fb402b0d992626c42bfee7a944dbbfe4624a922baffe6e0c6d5c2cb995170c9a6c74d5
7
- data.tar.gz: 194488b6bcb2ed5ce444c603789c6db5ce8b321f2ed15b70567f19b35afd7a0fb5e15cc78be828bf99d30809f0f23ea845a10d5b9da5d0949fe53db4ac43eae6
6
+ metadata.gz: bf6ec6f5b0376b4f2902d7c11b749b9d0ff9b62f3bb4d66a0b6d54164ee48a15a6cb7b78097604a9626e4226a310c77bea445a60b86770436e35900a6ac99484
7
+ data.tar.gz: d78c4e1005e41546958888b29a12b9bc004672b87edf03715d11ac88b9a670806dac093327fecf5f4d858aba3db926858f3c777f315a21cd1808aa2ffc54974e
@@ -1,11 +1,10 @@
1
1
  # TODO: the tags hash should be absent when there are no tags
2
- # TODO: optional timestamp parsing
3
2
  # TODO: time key shouldn't exist if there is no time
4
3
  # TODO: deal with improper line protocol
5
4
  class InfluxParser
6
5
  class << self
7
6
  def parse_point(s, options = {})
8
- default_options = {:parse_types => true}
7
+ default_options = {:parse_types => true, :time_format => nil}
9
8
  options = default_options.merge(options)
10
9
 
11
10
  point = {}
@@ -39,9 +38,10 @@ class InfluxParser
39
38
  point['values'][last_key] = unescape_point(value[1],options)
40
39
  end
41
40
  # puts "-----\n#{point['values'].to_yaml}\n"
41
+
42
42
  # check for a timestamp in the last value
43
43
  # TODO: I hate this, but it's late and I just want to move past it for now
44
- # TODO: what happens if the last character of the last value is an escaped quote?
44
+ # TODO: this level of nesting would fill rubocop with rage
45
45
  has_space = last_value_raw.rindex(/ /)
46
46
  if has_space
47
47
  time_stamp = last_value_raw[has_space+1..-1] # take everything from the space to the end
@@ -51,6 +51,11 @@ class InfluxParser
51
51
  # it was a timestamp, strip it from the last value and set the timestamp
52
52
  point['values'][last_key] = unescape_point(last_value_raw[0..has_space-1],options)
53
53
  point['time'] = time_stamp
54
+ if options[:time_format]
55
+ n_time = time_stamp.to_f / 1000000000
56
+ t = Time.at(n_time).utc
57
+ point['time'] = t.strftime(options[:time_format])
58
+ end
54
59
  end
55
60
  else
56
61
  point['time'] = nil
@@ -82,10 +82,22 @@ class TestParsePointFromDocs < Test::Unit::TestCase # def setup
82
82
 
83
83
  end
84
84
  def test_timestamp
85
+ # no timestamp
85
86
  point = InfluxParser.parse_point('weather,location=us-midwest temperature=82')
86
87
  assert_not_equal(false,point) # a straight up parse error will false
87
88
  assert_nil(point['time'])
88
- end
89
+
90
+ # unformatted time
91
+ point = InfluxParser.parse_point('weather,location=us-midwest temperature=82 1465839830100400200')
92
+ assert_not_equal(false,point) # a straight up parse error will false
93
+ assert_equal('1465839830100400200',point['time'])
94
+
95
+ # time
96
+ point = InfluxParser.parse_point('weather,location=us-midwest temperature=82 1465839830100400200',{:time_format => "%Y-%d-%mT%H:%M:%S.%NZ"})
97
+ assert_not_equal(false,point) # a straight up parse error will false
98
+ assert_equal('2016-13-06T17:43:50.100400209Z',point['time'])
99
+
100
+ end
89
101
 
90
102
  def test_float
91
103
  point = InfluxParser.parse_point('weather,location=us-midwest temperature=82 1465839830100400200')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Labrie