Class: Furigana::CLI
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #parse_options ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
10 11 12 13 |
# File 'lib/furigana/cli.rb', line 10 def initialize @settings = OpenStruct.new @settings.format = :text end |
Instance Method Details
#parse_options ⇒ Object
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/furigana/cli.rb', line 15 def OptionParser.new do |opts| opts. = "Usage: furigana [options] [file]" opts.on("--text", "Add furigana and output text (default)") do @settings.format = :text end opts.on("--html", "Add furigana and output HTML") do @settings.format = :html end opts.on("--yomikata", "Output yomikata only") do @settings.format = :yomikata end opts.on("--json", "Add furigana and output JSON") do @settings.format = :json end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts Furigana::VERSION exit end end.parse! end |
#start ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/furigana/cli.rb', line 42 def start input = ARGF.read case @settings.format when :text puts Formatter::Text.new(input, Reader.new.reading(input)).render when :html puts Formatter::HTML.new(input, Reader.new.reading(input)).render when :yomikata puts Formatter::Yomikata.new(input, Reader.new.reading(input)).render when :json puts Formatter::JSON.new(input, Reader.new.reading(input)).render end end |