Class: BaseHangul::CLI

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

Overview

Handle command line interfaces logic.

Instance Method Summary collapse

Constructor Details

#initializeCLI

Initialize a CLI.



7
8
9
# File 'lib/basehangul/cli.rb', line 7

def initialize
  @options = {}
end

Instance Method Details

#run(args = ARGV) ⇒ Object

Entry point for the application logic. Process command line arguments and run the BaseHangul.

args - An Array of Strings user passed.

Returns an Integer UNIX exit code.



17
18
19
20
21
22
23
24
25
26
# File 'lib/basehangul/cli.rb', line 17

def run(args = ARGV)
  @options, paths = Option.new.parse(args)
  source = paths.empty? ? $stdin.read : IO.read(paths[0])
  if @options[:decode]
    puts BaseHangul.decode(source)
  else
    puts BaseHangul.encode(source)
  end
  0
end