Class: Sijka::SijkaParser

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

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin) ⇒ SijkaParser

Returns a new instance of SijkaParser.



5
6
7
8
# File 'lib/sijka/parser.rb', line 5

def initialize(argv, stdin)
  @argv = argv
  @stdin = stdin
end

Instance Method Details

#parse_flagsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sijka/parser.rb', line 10

def parse_flags
  options = {}
  OptionParser.new do |opts|
    opts.banner = "Usage: sijka [name] [-h] [-f sijkafile] [-l]"
    opts.on("-l", "List available sijka files") do |sijkafile|
      options['list'] = true
    end
    opts.on("-f SIJKAFILE", "Specify a sijka file") do |sijkafile|
      options['sijkafile'] = sijkafile
    end
  end.parse!
  options
end

#parse_messageObject



24
25
26
27
28
29
30
# File 'lib/sijka/parser.rb', line 24

def parse_message
  if @argv.any?
    @argv.join(' ')
  else
    @stdin.tty? ? '' : @argv.read.chomp
  end
end