Permalink
Browse files

Fixing number field conversions.

  • Loading branch information...
1 parent aea997a commit fe6d2fbda6ac57b9d685cf3a47468ef90f866988 @JEG2 committed Jul 21, 2008
Showing with 19 additions and 1 deletion.
  1. +2 −1 lib/rrdb.rb
  2. +17 −0 test/tc_fetch.rb
View
@@ -240,7 +240,8 @@ def update(time, data)
create_database(time, safe_data.keys)
end
params = fields.map do |f|
- safe_data[f].send(safe_data[f].to_s =~ /\A\d+\./ ? :to_f : :to_i)
+ digits = safe_data[f].to_s.delete("^0-9.")
+ digits.send(digits.include?(".") ? :to_f : :to_i)
end
rrdtool(:update, "'#{time.to_i}:#{params.join(':')}'")
end
View
@@ -48,6 +48,23 @@ def test_example_data_from_tutorial
end
end
+ def test_all_fields_are_converted_to_numbers
+ RRDB.config( :reserve_fields => 0,
+ :database_start => Time.at(920804400),
+ :data_sources => { :comma => "GAUGE:600:U:U",
+ :kb => "GAUGE:600:U:U" },
+ :round_robin_archives => %w[AVERAGE:0.5:1:24] )
+
+ @db.update(Time.at(920804700), :comma => "17,000", :kb => "10 kb")
+ @db.update(Time.at(920805000), :comma => "17,000", :kb => "10 kb")
+
+ values = @db.fetch( :AVERAGE,
+ :start => Time.at(920804700),
+ :end => Time.at(920804700) ).values.first
+ assert_equal(17_000, values["comma"])
+ assert_equal(10, values["kb"])
+ end
+
def test_floats_are_supported
RRDB.config( :reserve_fields => 0,
:database_start => Time.at(920804400),

0 comments on commit fe6d2fb

Please sign in to comment.