Class: Justy::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



9
10
11
12
# File 'lib/justy/parser.rb', line 9

def initialize
  super
  init_parser
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#options_parserObject (readonly)

Returns the value of attribute options_parser.



7
8
9
# File 'lib/justy/parser.rb', line 7

def options_parser
  @options_parser
end

Instance Method Details

#init_parserObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/justy/parser.rb', line 14

def init_parser
  @options_parser = OptionParser.new do|opts|
    opts.banner = "Usage: justy [options]"
    opts.on('-t', '--type type', 'Search type. Must be md5 or filename.') do |type|
      @options[:type] = type;
    end

    opts.on('-r', '--relative', 'Relative to current folder') do
      @options[:relative] = true
    end

    opts.on('-f', '--folder folder', 'Search folder') do |folder|
      @options[:folder] = folder
    end

    opts.on('-h', '--help', 'Displays Help') do
      puts opts
      exit
    end
  end
end

#parse(args) ⇒ Object



36
37
38
39
40
# File 'lib/justy/parser.rb', line 36

def parse(args)
  @options = {:type => nil, :folder => nil, :relative => false }
  options_parser.parse!
  return options
end