Class: AsciiParadise::Sparky::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ascii_paradise/sparky/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(*i) ⇒ CLI

#

AsciiParadise::Sparky::CLI.run

Helper method to run an instance with the given arguments.

#

Returns:

  • (CLI)

    the instance that ran.

See Also:



21
22
23
24
25
# File 'lib/ascii_paradise/sparky/cli.rb', line 21

def self.run(*i)
  instance = new
  instance.run(*i)
  instance
end

Instance Method Details

#helpObject

#

help

Returns usage information for the sparkyc omponent.

#


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ascii_paradise/sparky/cli.rb', line 48

def help
  "
USAGE:
sparky [-h|--help] VALUE,...

EXAMPLES:
sparky 1 5 22 13 53
▁▁▃▂▇

sparky 0,30,55,80,33,150
▁▂▃▅▂▇

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

  "
end

#run(*i) ⇒ Object

#

run

Runs sparky with the given input argument.

The method will return nil.

#


34
35
36
37
38
39
40
41
# File 'lib/ascii_paradise/sparky/cli.rb', line 34

def run(*i)
  if i.empty? || (i.size == 1 && %w(-h --help).include?(i.first))
    puts help
  else
    sparkline = Sparky.new(i.map(&:to_f))
    puts sparkline.to_s
  end
end