Class: LyricsJapanese::CliLyricsJapanese

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

Overview

command line wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCliLyricsJapanese

Returns a new instance of CliLyricsJapanese.



13
14
15
# File 'lib/cli_lyrics_japanese.rb', line 13

def initialize
  @params = {}
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



11
12
13
# File 'lib/cli_lyrics_japanese.rb', line 11

def params
  @params
end

Instance Method Details

#define_options(opts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/cli_lyrics_japanese.rb', line 37

def define_options(opts)
  opts.version = VERSION
  opts.on_tail('-h', '--help', 'Show this message') do
    puts opts
    exit
  end
  opts.on_tail('-V', '--version', 'Show version') do
    puts opts.ver
    exit
  end
  opts.banner = <<~BANNER

    #{opts.ver}
    #{DESCRIPTION}
    Usage: #{opts.program_name}
  BANNER
  opts
end

#parse_optionsObject



17
18
19
20
21
22
# File 'lib/cli_lyrics_japanese.rb', line 17

def parse_options
  OptionParser.new do |opts|
    opts = define_options(opts)
    opts.parse!(ARGV, into: @params)
  end
end

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cli_lyrics_japanese.rb', line 24

def run
  text = []
  if !ARGV.empty?
    File.open(ARGV[0]) do |file|
      text = file.each_line.to_a
    end
  else
    text = STDIN.each_line.to_a
  end
  lines = LyricsJapanese.new.to_lyricruby(text, ' ')
  puts lines.join("\n")
end