Permalink
Browse files

Add optional format block to Sparkr.sparkline

Sparkr.sparkline can now be given an optional block which is then passed to
Sparkr::Sparkline#format.
  • Loading branch information...
rrrene committed Jan 29, 2014
1 parent 22f1086 commit 9082ab7cb7830f140a54865fe19b7523f97ee8c2
Showing with 29 additions and 2 deletions.
  1. +6 −2 lib/sparkr.rb
  2. +23 −0 test/sparkr_test.rb
View
@@ -5,7 +5,11 @@
require "sparkr/version"
module Sparkr
- def self.sparkline(*args)
- Sparkline.new(*args).to_s
+ def self.sparkline(*args, &block)
+ sparkline = Sparkline.new(*args)
+ if block
+ sparkline.format(&block)
+ end
+ sparkline.to_s
end
end
View
@@ -17,4 +17,27 @@
it "should find work with equal numbers" do
assert_sparkline '▁▁', [10, 10]
end
+
+
+ it ".sparkline should work with arity == 2" do
+ sparkline = Sparkr.sparkline([5.5,20]) do |tick, number|
+ if number < 6.0
+ tick = tick + "-"
+ else
+ tick
+ end
+ end
+ assert_equal '▁-█', sparkline
+ end
+
+ it ".sparkline should work with arity == 3" do
+ sparkline = Sparkr.sparkline([5.5,20]) do |tick, number, index|
+ if index == 1
+ tick = tick + "-"
+ else
+ tick
+ end
+ end
+ assert_equal '▁█-', sparkline
+ end
end

0 comments on commit 9082ab7

Please sign in to comment.