Git Product home page Git Product logo

sparkr's Introduction

Sparkr Build Status Code Climate

Sparkr is a port of spark for Ruby.

It lets you create ASCII sparklines for your Ruby CLIs: ▁▂▃▅▇

Installation

Add this line to your application's Gemfile:

gem 'sparkr'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sparkr

Usage

Shell

After installation, just run sparkr and pass it a list of numbers, like you would with spark. The output is what you would expect:

$ sparkr 0 30 55 80 33 150
▁▂▃▅▂▇

It is also possible to pipe data into sparkr:

$ echo 9 13 5 17 1 | sparkr
▄▆▂█▁

Ruby

The real reason for this port:

Sparkr.sparkline([0, 30, 55, 80, 33, 150])
# => "▁▂▃▅▂▇"

Coloring

Let's say you have your list of open and closed issues.

require 'sparkr'

open_issue_count = 3
closed_issue_count = 13

list = [open_issue_count, closed_issue_count]
puts "Issues: " + Sparkr.sparkline(list)
# => "Issues: ▁█"

But now you want to format the sparkline so that the open issues are red and the closed ones are green (to quickly see how you are doing).

Let's further suppose you use a gem that adds a #color method to String for ANSI coloring, like Term::ANSIColor.

require 'sparkr'
require 'term/ansicolor'

class String
  include Term::ANSIColor
end

open_issue_count = 3
closed_issue_count = 13

list = [open_issue_count, closed_issue_count]
sparkline = Sparkr.sparkline(list) do |tick, count, index|
  if index == 0
    tick.color(:red)
  else
    tick.color(:green)
  end
end
puts "Issues: " + sparkline
# => "Issues: ▁█" (colored, trust me)

To see how this looks live and in full colour, take a look at Inch.

Contributing

  1. Fork it ( http://github.com/rrrene/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

Author

René Föhring (@rrrene)

Credits

Sparkr would not exist without Zach Holman's spark.

License

Sparkr is released under the MIT License. See the LICENSE.txt file for further details.

sparkr's People

Contributors

rrrene avatar splattael avatar jeanlange avatar

Watchers

James Cloos avatar Christo De Lange avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.