lib/databox/integration.rb in databox-0.0.3 vs lib/databox/integration.rb in databox-0.1.0

- old
+ new

@@ -1,22 +1,24 @@ class Databox::Integration < Databox::Client - attr_accessor :name, :list, :date + attr_accessor :name, :list, :set_item, :date def initialize name, options={date: nil, id: nil} super() @name = name @date = options[:date] unless options[:date].nil? @token = options[:id] unless options[:id].nil? @list = [] + @set_item = nil end def save if push(to_data).success? @list = [] + @set_item = nil true else false end end @@ -51,10 +53,73 @@ ] end end + + + #TODO: Add support for icons #TODO: Add support for changes class Databox::Funnel < Databox::Pipeline; end; class Databox::Pie < Databox:: Pipeline; end; + + +class Databox::Progress < Databox::Integration + + def add *args + raise "Progress does not support add!" + end + + def set message, max, value + @set_item = [message, max, value] + end + + def to_data + [ + { key: "#{name}@label", value: @set_item.first }, + { key: "#{name}@max_value", value: @set_item[1] }, + { key: "#{name}", value: @set_item.last }, + ] + end + +end + + + +class Databox::BigNumber < Databox::Integration + def set number, date=nil + date ||= @date + @set_item = [number, date] + end + + def to_data + out = {key: name, value: @set_item.first} + out.merge!({date: @set_item[1]}) unless @set_item[1].nil? + out + end +end + + + +class Databox::LineChart < Databox::Integration + + def add value, date=nil + date ||= @date + @list.push [value, date] + end + + def to_data + @list.map do |i| + out = {key: name, value: i.first} + out.merge!({date: i[1]}) unless i[1].nil? + out + end + end +end + +class Databox::BarChart < Databox::LineChart; end; + +class Databox::Compare < Databox::LineChart; end; + +class Databox::Interval < Databox::LineChart; end;