rspark-spark 1.0.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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/rspark +45 -0
- data/bin/setup +8 -0
- data/lib/rspark/spark.rb +52 -0
- data/lib/rspark/spark/version.rb +5 -0
- data/rspark-spark.gemspec +26 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a67c01e9b6466aaeaaa7be048e78956960e4aa9
|
4
|
+
data.tar.gz: fc0e48da68eb65f6556310419fc55c57144004a5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c22fbf6b867ff5bf7ff5bb69aa727f5a1a2558e62ab9c2a0da1dd62d22e868f3c0e051ea760fd3115de9afed29a7c4a06a5036d7d6260ebfa49c76a808ac0fa0
|
7
|
+
data.tar.gz: d764456889931f5aed439e3e860a99d8d6deffa4b1e55c45eaa2ca466ce873b95ed5380ec7fe6cc1688cefe608e61ab949bc7531737975c4e32d564802382b10
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Radu-Bogdan Croitoru
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Rspark::Spark
|
2
|
+
|
3
|
+
Displays beautiful graphs to use in the terminal.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rspark-spark'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rspark-spark
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
**From Ruby**
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
s = Rspark::Spark.new(
|
27
|
+
values: [1,2,3]
|
28
|
+
)
|
29
|
+
s.pretty_print
|
30
|
+
```
|
31
|
+
|
32
|
+
- values: array of numbers (mandatory)
|
33
|
+
- max: maximum number (optional - default to max number in values)
|
34
|
+
- direction: horizontal/vertical (optional - default horizontal)
|
35
|
+
|
36
|
+
**From terminal**
|
37
|
+
|
38
|
+
Just run rspark and pass it a list of numbers (comma-delimited or spaces).
|
39
|
+
|
40
|
+
```
|
41
|
+
rspark 0 30 55 80 33 150
|
42
|
+
▁▂▃▅▂▇
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/radubogdan/rspark-spark.
|
52
|
+
|
53
|
+
|
54
|
+
## Thanks
|
55
|
+
|
56
|
+
Inspired from [holman/spark](https://github.com/holman/spark)
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/rspark
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rspark/spark'
|
3
|
+
|
4
|
+
# Helpers
|
5
|
+
def help
|
6
|
+
puts "\nRspark - Sparklines for your shell"
|
7
|
+
puts "\nARGUMENTS:"
|
8
|
+
puts " - values (mandatory) - comma separated"
|
9
|
+
puts " - direction (optional) - -h or -v)"
|
10
|
+
puts "\USAGE:"
|
11
|
+
puts " - rspark 1 2 3 4 5"
|
12
|
+
puts " - rspark 1 2 3 4 5 -v"
|
13
|
+
puts "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def allowed_directions
|
17
|
+
{
|
18
|
+
"-v" => "vertical",
|
19
|
+
"-h" => "horizontal"
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
if not STDIN.tty? and not STDIN.closed?
|
24
|
+
arr = ARGF.read.strip.split(' ').map(&:to_i)
|
25
|
+
spark = Rspark::Spark.new(values: arr)
|
26
|
+
puts spark.pretty_print
|
27
|
+
else
|
28
|
+
case ARGV.length
|
29
|
+
when 0
|
30
|
+
help
|
31
|
+
else
|
32
|
+
possible_direction = ARGV.pop
|
33
|
+
|
34
|
+
if allowed_directions.keys.include?(possible_direction)
|
35
|
+
arr = ARGV.map(&:to_i)
|
36
|
+
spark = Rspark::Spark.new(values: arr, direction: allowed_directions[possible_direction])
|
37
|
+
puts spark.pretty_print
|
38
|
+
elsif possible_direction.to_i.class == Fixnum
|
39
|
+
arr = ARGV.map(&:to_i)
|
40
|
+
arr << possible_direction.to_i
|
41
|
+
spark = Rspark::Spark.new(values: arr)
|
42
|
+
puts spark.pretty_print
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/bin/setup
ADDED
data/lib/rspark/spark.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rspark/spark/version"
|
2
|
+
|
3
|
+
module Rspark
|
4
|
+
class Spark
|
5
|
+
attr_accessor :max, :direction
|
6
|
+
attr_reader :values
|
7
|
+
|
8
|
+
HGRAPH = %w(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
|
9
|
+
VGRAPH = %w(▏ ▎ ▍ ▌ ▋ ▊ ▉ █)
|
10
|
+
|
11
|
+
def initialize(options={})
|
12
|
+
@values = options[:values]
|
13
|
+
@max = options[:max] || @values.max
|
14
|
+
@direction = options[:direction] || "horizontal"
|
15
|
+
end
|
16
|
+
|
17
|
+
def values=(new_values)
|
18
|
+
@values = new_values
|
19
|
+
@max = @values.max
|
20
|
+
end
|
21
|
+
|
22
|
+
def pretty_print
|
23
|
+
generate_result(@direction)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def bar(num, max, graph)
|
29
|
+
index = num * (graph.length - 1) / max
|
30
|
+
graph[index]
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_result(direction)
|
34
|
+
if @max < @values.max
|
35
|
+
return "Your maximum is less than the maximum value found in values"
|
36
|
+
end
|
37
|
+
|
38
|
+
result = ""
|
39
|
+
case direction
|
40
|
+
when "horizontal"
|
41
|
+
@values.each do |value|
|
42
|
+
result += bar(value, @max, HGRAPH)
|
43
|
+
end
|
44
|
+
when "vertical"
|
45
|
+
@values.each do |value|
|
46
|
+
result = result + bar(value, @max, VGRAPH) + "\n"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspark/spark/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rspark-spark"
|
8
|
+
spec.version = Rspark::Spark::VERSION
|
9
|
+
spec.authors = ["Radu-Bogdan Croitoru"]
|
10
|
+
spec.email = ["croitoruradubogdan@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Sparklines for your shell}
|
13
|
+
spec.description = %q{Displays beautiful graphs to use in the terminal}
|
14
|
+
spec.homepage = "https://github.com/radubogdan/rspark-spark"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspark-spark
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Radu-Bogdan Croitoru
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-26 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Displays beautiful graphs to use in the terminal
|
70
|
+
email:
|
71
|
+
- croitoruradubogdan@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/rspark
|
85
|
+
- bin/setup
|
86
|
+
- lib/rspark/spark.rb
|
87
|
+
- lib/rspark/spark/version.rb
|
88
|
+
- rspark-spark.gemspec
|
89
|
+
homepage: https://github.com/radubogdan/rspark-spark
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Sparklines for your shell
|
113
|
+
test_files: []
|