sparkr 0.2.0 → 0.3.1

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: c8dd99340dc0555b7c2a29e091f62e406fbe5233
4
- data.tar.gz: 2bda5d1efce7cca0959a8a03805a20b20b9266ef
3
+ metadata.gz: c95e929d69cab1b4cbaafa7a6a143de064b6a91b
4
+ data.tar.gz: e7aaa6685c613f0ad95841690b4c8f5f1569af2d
5
5
  SHA512:
6
- metadata.gz: f886432e12a6623ec1bf5554518d482c9beeabbf80781c6ab18df3439aa10811366c161aad33f9d212bd842196728e8ecd4b3cf316f918fb905591a86bbf88cb
7
- data.tar.gz: 257c9d14e88ac0abb66de3118c92fe73cc548a064987ea296d61b50ccd2712f32b5e3d725445ca945f17ce2435eb5b518c3cf3bf6d8986dea3d0d4cf503571fb
6
+ metadata.gz: 59167787dafcbead72b2b489c7aaa125fc0f9e6fb81365ffdb34ba03b1a684c1d8e83eb64f63e203a3fe51caddbb86831549d3c1e7ee931b972a675c017965c4
7
+ data.tar.gz: 6fc3c59056ecd29cdae48212c186c299e0449ee180cef5645444fe1f56321b2ff4eff344378624ada3a220967e53d937c35ec59a6949649f50a829cbac05c520
data/README.md CHANGED
@@ -6,6 +6,7 @@ Sparkr is a port of [spark](https://github.com/holman/spark) for Ruby.
6
6
 
7
7
  It let's you create ASCII sparklines for your Ruby CLIs: ▁▂▃▅▇
8
8
 
9
+
9
10
  ## Installation
10
11
 
11
12
  Add this line to your application's Gemfile:
@@ -40,6 +41,34 @@ The real reason for this port:
40
41
  # => "▁▂▃▅▂▇"
41
42
 
42
43
 
44
+ ### Coloring
45
+
46
+ Let's say you have your list of open and closed issues.
47
+
48
+ list = [open_issue_count, closed_issue_count]
49
+ Sparkr.sparkline(list)
50
+ # => "▁█"
51
+
52
+ But now you want to format the sparkline so that the open issues are red
53
+ and the closed ones are green (to quickly see how you are doing).
54
+
55
+ Let's further suppose you use a gem that adds a `#color` method to `String`
56
+ for ANSI coloring, like
57
+ [Term::ANSIColor](https://github.com/flori/term-ansicolor).
58
+
59
+ Sparkr.sparkline(list) do |tick, count, index|
60
+ if index == 0
61
+ tick.color(:red)
62
+ else
63
+ tick.color(:green)
64
+ end
65
+ end
66
+ # => "▁█" (colored, trust me)
67
+
68
+ To see how this looks live and in full colour, take a look at
69
+ [Inch](http://rrrene.github.io/inch).
70
+
71
+
43
72
  ## Contributing
44
73
 
45
74
  1. Fork it ( http://github.com/rrrene/sparkr/fork )
@@ -5,7 +5,42 @@ require "sparkr/sparkline"
5
5
  require "sparkr/version"
6
6
 
7
7
  module Sparkr
8
- def self.sparkline(*args)
9
- Sparkline.new(*args).to_s
8
+ # Returns a sparkline
9
+ #
10
+ # Example:
11
+ #
12
+ # list = [open_issue_count, closed_issue_count]
13
+ # Sparkr.sparkline(list)
14
+ # # => "▁█"
15
+ #
16
+ # Example with block:
17
+ #
18
+ # Let's say you have your list of open and closed issues, but you
19
+ # want to format it so the open ones are red and the closed ones are
20
+ # green, so you can quickly see how you are doing. Let's further
21
+ # suppose you use a gem that adds a #color method to String
22
+ # for ANSI coloring.
23
+ #
24
+ # line = Sparkr.sparkline(list) do |tick, count, index|
25
+ # if index == 0
26
+ # tick.color(:red)
27
+ # else
28
+ # tick.color(:green)
29
+ # end
30
+ # end
31
+ #
32
+ # line
33
+ # # => "▁█" (colored, trust me)
34
+ #
35
+ # @param numbers [Array<String,Fixnum,Float>] the numbers to be rendered
36
+ # @param &block [Proc] optional, can be used to format the rendered string
37
+ #
38
+ # @return [String]
39
+ def self.sparkline(numbers, &block)
40
+ sparkline = Sparkline.new(numbers)
41
+ if block
42
+ sparkline.format(&block)
43
+ end
44
+ sparkline.to_s
10
45
  end
11
46
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Sparkr
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["rf@bamaru.de"]
11
11
  spec.summary = %w{ASCII Sparklines in Ruby}
12
12
  spec.description = %q{ASCII Sparklines in Ruby}
13
- spec.homepage = ""
13
+ spec.homepage = "http://trivelop.de/sparkr/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
4
4
 
5
5
  describe ::Sparkr::CLI do
6
6
  it "should find work" do
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
4
+
5
+ describe ::Sparkr::Sparkline do
6
+
7
+ it "format should work with arity == 2" do
8
+ sparkline = Sparkr::Sparkline.new([5.5,20])
9
+ sparkline.format do |tick, number|
10
+ if number < 6.0
11
+ tick = tick + "-"
12
+ else
13
+ tick
14
+ end
15
+ end
16
+ assert_equal '▁-█', sparkline.to_s
17
+ end
18
+
19
+ it "format should work with arity == 3" do
20
+ sparkline = Sparkr::Sparkline.new([5.5,20])
21
+ sparkline.format do |tick, number, index|
22
+ if index == 1
23
+ tick = tick + "-"
24
+ else
25
+ tick
26
+ end
27
+ end
28
+ assert_equal '▁█-', sparkline.to_s
29
+ end
30
+ end
@@ -18,27 +18,26 @@ describe ::Sparkr do
18
18
  assert_sparkline '▁▁', [10, 10]
19
19
  end
20
20
 
21
- it "format should work with arity == 2" do
22
- sparkline = Sparkr::Sparkline.new([5.5,20])
23
- sparkline.format do |tick, number|
21
+
22
+ it ".sparkline should work with arity == 2" do
23
+ sparkline = Sparkr.sparkline([5.5,20]) do |tick, number|
24
24
  if number < 6.0
25
25
  tick = tick + "-"
26
26
  else
27
27
  tick
28
28
  end
29
29
  end
30
- assert_equal '▁-█', sparkline.to_s
30
+ assert_equal '▁-█', sparkline
31
31
  end
32
32
 
33
- it "format should work with arity == 3" do
34
- sparkline = Sparkr::Sparkline.new([5.5,20])
35
- sparkline.format do |tick, number, index|
33
+ it ".sparkline should work with arity == 3" do
34
+ sparkline = Sparkr.sparkline([5.5,20]) do |tick, number, index|
36
35
  if index == 1
37
36
  tick = tick + "-"
38
37
  else
39
38
  tick
40
39
  end
41
40
  end
42
- assert_equal '▁█-', sparkline.to_s
41
+ assert_equal '▁█-', sparkline
43
42
  end
44
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - René Föhring
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-22 00:00:00.000000000 Z
11
+ date: 2014-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,10 +60,11 @@ files:
60
60
  - lib/sparkr/sparkline.rb
61
61
  - lib/sparkr/version.rb
62
62
  - sparkr.gemspec
63
- - test/cli_test.rb
63
+ - test/sparkr/cli_test.rb
64
+ - test/sparkr/sparkline_test.rb
64
65
  - test/sparkr_test.rb
65
66
  - test/test_helper.rb
66
- homepage: ''
67
+ homepage: http://trivelop.de/sparkr/
67
68
  licenses:
68
69
  - MIT
69
70
  metadata: {}
@@ -88,6 +89,7 @@ signing_key:
88
89
  specification_version: 4
89
90
  summary: '["ASCII", "Sparklines", "in", "Ruby"]'
90
91
  test_files:
91
- - test/cli_test.rb
92
+ - test/sparkr/cli_test.rb
93
+ - test/sparkr/sparkline_test.rb
92
94
  - test/sparkr_test.rb
93
95
  - test/test_helper.rb