sparkr 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +9 -0
- data/bin/sparkr +11 -0
- data/lib/sparkr.rb +9 -0
- data/lib/sparkr/cli.rb +7 -0
- data/lib/sparkr/sparkline.rb +19 -0
- data/lib/sparkr/version.rb +3 -0
- data/sparkr.gemspec +23 -0
- data/test/cli_test.rb +12 -0
- data/test/sparkr_test.rb +14 -0
- data/test/test_helper.rb +15 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a37bdfe0c66bc29bf3f9b61ee747c92353fed0c7
|
4
|
+
data.tar.gz: be8bb033d057fec37216982df48e5b70f6d02b14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5358e3b58d18bc6e653f1fb18fa73cbe47cfd77f03e553f901edcdd5f59bb8d4c08e337ef8bb88065012918406edd53dda9554b84668a41b33934a316d7e2cbf
|
7
|
+
data.tar.gz: f7e1322e94d506099a01c21a25e891a66be455343078f121e5f1d455a06a6335373055ca59736894a8fabf3da56dab3b014993661f941aed49028d2bc31d93fb
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sparkr
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 René Föhring
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Sparkr
|
2
|
+
|
3
|
+
Sparkr is a port of [spark](https://github.com/holman/spark) for Ruby.
|
4
|
+
|
5
|
+
It let's you create sparklines for your Ruby CLIs: ▁▂▃▅▇
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sparkr'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sparkr
|
20
|
+
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Shell
|
25
|
+
|
26
|
+
After installation, just run `sparkr` and pass it a list of numbers, like
|
27
|
+
you would with [spark](https://github.com/holman/spark). The output is what
|
28
|
+
you would expect:
|
29
|
+
|
30
|
+
$ sparkr 0 30 55 80 33 150
|
31
|
+
▁▂▃▅▂▇
|
32
|
+
|
33
|
+
### Ruby
|
34
|
+
|
35
|
+
The real reason for this port:
|
36
|
+
|
37
|
+
Sparkr.sparkline([0,30,55,80,33,150])
|
38
|
+
# => "▁▂▃▅▂▇"
|
39
|
+
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( http://github.com/rrrene/sparkr/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
48
|
+
|
49
|
+
|
50
|
+
## Author
|
51
|
+
|
52
|
+
René Föhring (@rrrene)
|
53
|
+
|
54
|
+
|
55
|
+
## Credits
|
56
|
+
|
57
|
+
Sparkr would not exist without Zach Holman's [spark](https://github.com/holman/spark).
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
Sparkr is released under the MIT License. See the LICENSE.txt file for further
|
63
|
+
details.
|
data/Rakefile
ADDED
data/bin/sparkr
ADDED
data/lib/sparkr.rb
ADDED
data/lib/sparkr/cli.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sparkr
|
2
|
+
class Sparkline
|
3
|
+
TICKS = %w(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
|
4
|
+
|
5
|
+
def initialize(_numbers)
|
6
|
+
numbers = _numbers.map(&:to_i)
|
7
|
+
step_height = (numbers.max - numbers.min) / (TICKS.size - 1).to_f
|
8
|
+
|
9
|
+
@ticks = numbers.map do |n|
|
10
|
+
index = ((n - numbers.min) / step_height).to_i
|
11
|
+
TICKS[index]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@ticks.join('')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/sparkr.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sparkr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sparkr"
|
8
|
+
spec.version = Sparkr::VERSION
|
9
|
+
spec.authors = ["René Föhring"]
|
10
|
+
spec.email = ["rf@bamaru.de"]
|
11
|
+
spec.summary = %w{Sparklines in your shell, in Ruby}
|
12
|
+
spec.description = %q{Sparklines in your shell, in Ruby}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/test/cli_test.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
describe ::Sparkr::CLI do
|
4
|
+
it "should find work" do
|
5
|
+
out, err = capture_io do
|
6
|
+
::Sparkr::CLI.run("1", "2", "3", "4", "100", "5", "10", "20", "50", "300")
|
7
|
+
end
|
8
|
+
refute out.empty?, "there should be some output"
|
9
|
+
assert err.empty?, "there should be no errors"
|
10
|
+
assert_equal "▁▁▁▁▃▁▁▁▂█\n", out
|
11
|
+
end
|
12
|
+
end
|
data/test/sparkr_test.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
2
|
+
|
3
|
+
describe ::Sparkr do
|
4
|
+
it "should find work" do
|
5
|
+
assert_sparkline '▁▂▃▄▅▆▇█', Sparkr.sparkline([1,2,3,4,5,6,7,8])
|
6
|
+
assert_sparkline '▁▂█▅▂', Sparkr.sparkline([1,5,22,13,5])
|
7
|
+
assert_sparkline '▁█', Sparkr.sparkline([5.5,20])
|
8
|
+
assert_sparkline '▁▁▁▁▃▁▁▁▂█', Sparkr.sparkline([1,2,3,4,100,5,10,20,50,300])
|
9
|
+
assert_sparkline '▁▄█', Sparkr.sparkline([1,50,100])
|
10
|
+
assert_sparkline '▁▃█', Sparkr.sparkline([2,4,8])
|
11
|
+
assert_sparkline '▁▂▃▄▂█', Sparkr.sparkline([0,30,55,80,33,150])
|
12
|
+
assert_sparkline '▁▂▄▆█', Sparkr.sparkline([1,2,3,4,5])
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
+
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'bundler'
|
9
|
+
Bundler.require
|
10
|
+
|
11
|
+
def assert_sparkline(expected, actual)
|
12
|
+
assert actual.index('▁'), "there must be a minimum"
|
13
|
+
assert actual.index('█'), "there must be a maximum"
|
14
|
+
assert_equal expected, actual
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sparkr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- René Föhring
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Sparklines in your shell, in Ruby
|
42
|
+
email:
|
43
|
+
- rf@bamaru.de
|
44
|
+
executables:
|
45
|
+
- sparkr
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .ruby-gemset
|
51
|
+
- .ruby-version
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/sparkr
|
57
|
+
- lib/sparkr.rb
|
58
|
+
- lib/sparkr/cli.rb
|
59
|
+
- lib/sparkr/sparkline.rb
|
60
|
+
- lib/sparkr/version.rb
|
61
|
+
- sparkr.gemspec
|
62
|
+
- test/cli_test.rb
|
63
|
+
- test/sparkr_test.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
homepage: ''
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: '["Sparklines", "in", "your", "shell,", "in", "Ruby"]'
|
89
|
+
test_files:
|
90
|
+
- test/cli_test.rb
|
91
|
+
- test/sparkr_test.rb
|
92
|
+
- test/test_helper.rb
|