Class: LyricsJapanese::CliLyricsJapanese
- Inherits:
-
Object
- Object
- LyricsJapanese::CliLyricsJapanese
- Defined in:
- lib/cli_lyrics_japanese.rb
Overview
command line wrapper
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #define_options(opts) ⇒ Object
-
#initialize ⇒ CliLyricsJapanese
constructor
A new instance of CliLyricsJapanese.
- #parse_options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ CliLyricsJapanese
Returns a new instance of CliLyricsJapanese.
13 14 15 |
# File 'lib/cli_lyrics_japanese.rb', line 13 def initialize @params = {} end |
Instance Attribute Details
#params ⇒ Object
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 (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 #{opts.ver} #{DESCRIPTION} Usage: #{opts.program_name} BANNER opts end |
#parse_options ⇒ Object
17 18 19 20 21 22 |
# File 'lib/cli_lyrics_japanese.rb', line 17 def OptionParser.new do |opts| opts = (opts) opts.parse!(ARGV, into: @params) end end |
#run ⇒ Object
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 |