Class: Artii::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/artii/cli.rb', line 7

def initialize(*args)
  @params = {}
  @action = :output

  OptionParser.new do |opts|
    opts.banner = "Usage: artii 'your string here' [-f FONT_NAME or --font FONT_NAME] [-l or --list]"

    opts.on('-f', '--font FONT_NAME', 'Specify the font to be used (defaults to "big")') do |font|
      @params[:font] = font
    end

    opts.on('-l', '--list', 'Prints the list of available fonts') do |list|
      @action = :list_all_fonts
    end

    opts.on('-v', '--version', 'Displays current version number') do |version|
      @action = :version
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    if args.empty?
      puts opts
      exit
    end
  end.parse!(args)

  @params[:text] = args.join " "

  @a = Artii::Base.new(@params)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



6
7
8
# File 'lib/artii/cli.rb', line 6

def action
  @action
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/artii/cli.rb', line 6

def params
  @params
end

Instance Method Details

#font_nameObject



42
43
44
# File 'lib/artii/cli.rb', line 42

def font_name
  @a.font_name
end

#outputObject



46
47
48
49
50
51
52
# File 'lib/artii/cli.rb', line 46

def output
  if @action == :output
    @a.send @action, @params[:text]
  else
    @a.send @action
  end
end