Permalink
Browse files

Add better docs

  • Loading branch information...
1 parent 9082ab7 commit edd63417332a956559cbac92dabb075e7282bd8e @rrrene committed Jan 29, 2014
Showing with 33 additions and 2 deletions.
  1. +33 −2 lib/sparkr.rb
View
@@ -5,8 +5,39 @@
require "sparkr/version"
module Sparkr
- def self.sparkline(*args, &block)
- sparkline = Sparkline.new(*args)
+ # Returns a sparkline
+ #
+ # Example:
+ #
+ # list = [open_issue_count, closed_issue_count]
+ # Sparkr.sparkline(list)
+ # # => "▁█"
+ #
+ # Example with block:
+ #
+ # Let's say you have your list of open and closed issues, but you
+ # want to format it so the open ones are red and the closed ones are
+ # green, so you can quickly see how you are doing. Let's further
+ # suppose you use a gem that adds a #color method to String
+ # for ANSI coloring.
+ #
+ # line = Sparkr.sparkline(list) do |tick, count, index|
+ # if index == 0
+ # tick.color(:red)
+ # else
+ # tick.color(:green)
+ # end
+ # end
+ #
+ # line
+ # # => "▁█" (colored, trust me)
+ #
+ # @param numbers [Array<String,Fixnum,Float>] the numbers to be rendered
+ # @param &block [Proc] optional, can be used to format the rendered string
+ #
+ # @return [String]
+ def self.sparkline(numbers, &block)
+ sparkline = Sparkline.new(numbers)
if block
sparkline.format(&block)
end

0 comments on commit edd6341

Please sign in to comment.