Class: Sijka::SijkaParser
- Inherits:
-
Object
- Object
- Sijka::SijkaParser
- Defined in:
- lib/sijka/parser.rb
Instance Method Summary collapse
-
#initialize(argv, stdin) ⇒ SijkaParser
constructor
A new instance of SijkaParser.
- #parse_flags ⇒ Object
- #parse_message ⇒ Object
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_flags ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sijka/parser.rb', line 10 def parse_flags = {} OptionParser.new do |opts| opts. = 'Usage: sijka [name] [-h] [-f sijkafile] [-l]' opts.on('-l', 'List available sijka files') do |_| ['list'] = true end opts.on('-f SIJKAFILE', 'Specify a sijka file') do |sijkafile| ['sijkafile'] = sijkafile end opts.on('-r', 'Random file') do |_| ['sijkafile'] = Sijka::FILE_LIST.sample end end.parse! end |
#parse_message ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sijka/parser.rb', line 27 def if @argv.any? @argv.join(' ') else @stdin.tty? ? '' : @argv.read.chomp end end |