Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
encode 0 with a max of 0 with all encoding types
Browse files Browse the repository at this point in the history
  • Loading branch information
raykrueger committed Mar 5, 2010
1 parent 248fd24 commit 412b6cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/google_chart.rb
Expand Up @@ -24,10 +24,10 @@ def encode(encoding, n, max)
case encoding case encoding
when :simple when :simple
return "_" if n.nil? return "_" if n.nil?
SIMPLE_CHARS[((n/max.to_f) * (SIMPLE_CHARS.size - 1)).round] SIMPLE_CHARS[((n.zero? ? 0 : n/max.to_f) * (SIMPLE_CHARS.size - 1)).round]
when :text when :text
return "-1" if n.nil? return "-1" if n.nil?
((((n/max.to_f) * 1000.0).round)/10.0).to_s ((((n.zero? ? 0 : n/max.to_f) * 1000.0).round)/10.0).to_s
when :extended when :extended
return "__" if n.nil? return "__" if n.nil?
EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round] EXTENDED_PAIRS[max.zero? ? 0 : ((n/max.to_f) * (EXTENDED_PAIRS.size - 1)).round]
Expand Down
10 changes: 9 additions & 1 deletion spec/gchartrb_spec.rb
Expand Up @@ -111,7 +111,15 @@ class <<self ; public :new ; end
GoogleChart.encode(:extended, nil, 1).should == "__" GoogleChart.encode(:extended, nil, 1).should == "__"
end end


it "encodes 0 with a max of 0 correctly" do it "encodes 0 with a max of 0 correctly using extended" do
GoogleChart.encode(:extended, 0, 0).should == "AA" GoogleChart.encode(:extended, 0, 0).should == "AA"
end end

it "encodes 0 with a max of 0 correctly using simple" do
GoogleChart.encode(:simple, 0, 0).should == "A"
end

it "encodes 0 with a max of 0 correctly using text" do
GoogleChart.encode(:text, 0, 0).should == "0.0"
end
end end

0 comments on commit 412b6cb

Please sign in to comment.