Skip to content

Commit

Permalink
▁▂▃▅▂▇
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Jan 21, 2014
0 parents commit 9da8aea
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
1 change: 1 addition & 0 deletions .ruby-gemset
@@ -0,0 +1 @@
Sparkr
1 change: 1 addition & 0 deletions .ruby-version
@@ -0,0 +1 @@
ruby-2.0.0
6 changes: 6 additions & 0 deletions Gemfile
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in homecoming.gemspec
gemspec

gem 'simplecov', :require => false, :group => :test
22 changes: 22 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,22 @@
Copyright (c) 2014 René Föhring

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
@@ -0,0 +1,29 @@
# Sparkr

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'Sparkr'

And then execute:

$ bundle

Or install it yourself as:

$ gem install Sparkr

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( http://github.com/<my-github-username>/Sparkr/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
9 changes: 9 additions & 0 deletions Rakefile
@@ -0,0 +1,9 @@
require "bundler/gem_tasks"

require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = "test/**/*_test.rb"
end

task :default => :test
11 changes: 11 additions & 0 deletions bin/sparkr
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby

require 'bundler'
begin
Bundler.require
rescue Bundler::GemfileNotFound
require 'Sparkr'
end

require 'Sparkr'
Sparkr::CLI.run(*ARGV)
9 changes: 9 additions & 0 deletions lib/sparkr.rb
@@ -0,0 +1,9 @@
require "sparkr/cli"
require "sparkr/sparkline"
require "sparkr/version"

module Sparkr
def self.sparkline(*args)
Sparkline.new(*args).to_s
end
end
7 changes: 7 additions & 0 deletions lib/sparkr/cli.rb
@@ -0,0 +1,7 @@
module Sparkr
class CLI
def self.run(*args)
puts Sparkline.new(args.map(&:to_f)).to_s
end
end
end
24 changes: 24 additions & 0 deletions lib/sparkr/sparkline.rb
@@ -0,0 +1,24 @@
require 'pry'

module Sparkr
class Sparkline
TICKS = %w( )

def initialize(numbers)
@step_count = TICKS.size
@step_height = (numbers.max - numbers.min) / @step_count + 1

indexes = numbers.map do |n|
((n - numbers.min) / @step_height).to_i
end
@ticks = indexes.map do |index|
TICKS[index]
end
binding.pry
end

def to_s
@ticks.join('')
end
end
end
3 changes: 3 additions & 0 deletions lib/sparkr/version.rb
@@ -0,0 +1,3 @@
module Sparkr
VERSION = "0.0.1"
end
24 changes: 24 additions & 0 deletions sparkr.gemspec
@@ -0,0 +1,24 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'sparkr/version'

Gem::Specification.new do |spec|
spec.name = "sparkr"
spec.version = Sparkr::VERSION
spec.authors = ["René Föhring"]
spec.email = ["rf@bamaru.de"]
spec.summary = %w{Sparklines in your shell, in Ruby}
spec.description = %q{Sparklines in your shell, in Ruby}
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "pry"
end
21 changes: 21 additions & 0 deletions test/sparkr_test.rb
@@ -0,0 +1,21 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper')

describe ::Sparkr do
it "should find work" do
puts Sparkr.sparkline([1,5,22,13,5])
puts Sparkr.sparkline([0,30,55,80,33,150])
puts Sparkr.sparkline([5.5,20])
puts Sparkr.sparkline([1,2,3,4,100,5,10,20,50,300])
puts Sparkr.sparkline([1,50,100])
puts Sparkr.sparkline([2,4,8])
puts Sparkr.sparkline([1,2,3,4,5])

assert_equal '▁▂█▅▂', Sparkr.sparkline([1,5,22,13,5])
assert_equal '▁▂▃▅▂▇', Sparkr.sparkline([0,30,55,80,33,150])
assert_equal '▁█', Sparkr.sparkline([5.5,20])
assert_equal '▁▁▁▁▃▁▁▁▂█', Sparkr.sparkline([1,2,3,4,100,5,10,20,50,300])
assert_equal '▁▄█', Sparkr.sparkline([1,50,100])
assert_equal '▁▃█', Sparkr.sparkline([2,4,8])
assert_equal '▁▂▄▆█', Sparkr.sparkline([1,2,3,4,5])
end
end
13 changes: 13 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,13 @@
require 'simplecov'
SimpleCov.start

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'minitest/spec'
require 'minitest/autorun'
require 'bundler'
Bundler.require

def fixture_path(name)
File.join(File.dirname(__FILE__), "fixtures", name.to_s)
end

0 comments on commit 9da8aea

Please sign in to comment.