Permalink
Browse files

▁▂▃▅▂▇

  • Loading branch information...
0 parents commit 9da8aeaa64ff21daa1b39e3493134d42d67eb71a @rrrene committed Jan 21, 2014
Showing with 197 additions and 0 deletions.
  1. +17 −0 .gitignore
  2. +1 −0 .ruby-gemset
  3. +1 −0 .ruby-version
  4. +6 −0 Gemfile
  5. +22 −0 LICENSE.txt
  6. +29 −0 README.md
  7. +9 −0 Rakefile
  8. +11 −0 bin/sparkr
  9. +9 −0 lib/sparkr.rb
  10. +7 −0 lib/sparkr/cli.rb
  11. +24 −0 lib/sparkr/sparkline.rb
  12. +3 −0 lib/sparkr/version.rb
  13. +24 −0 sparkr.gemspec
  14. +21 −0 test/sparkr_test.rb
  15. +13 −0 test/test_helper.rb
@@ -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
@@ -0,0 +1 @@
+Sparkr
@@ -0,0 +1 @@
+ruby-2.0.0
@@ -0,0 +1,6 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in homecoming.gemspec
+gemspec
+
+gem 'simplecov', :require => false, :group => :test
@@ -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.
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -0,0 +1,7 @@
+module Sparkr
+ class CLI
+ def self.run(*args)
+ puts Sparkline.new(args.map(&:to_f)).to_s
+ end
+ end
+end
@@ -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
@@ -0,0 +1,3 @@
+module Sparkr
+ VERSION = "0.0.1"
+end
@@ -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
@@ -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
@@ -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.