Module: Parser

Defined in:
lib/mailchekka/parser.rb

Defined Under Namespace

Classes: Options

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



15
16
17
# File 'lib/mailchekka/parser.rb', line 15

def options=(value)
  @options = value
end

Class Method Details

.opt_parserObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mailchekka/parser.rb', line 24

def self.opt_parser
  @parser ||= OptionParser.new do |parser|
    parser.banner = 'Usage: mailchecker [options]'
    parser.separator ''
    parser.on('-t', '--host HOST', String, '#Mail service host.') do |host|
      @options.host = host
    end

    parser.on('-p', '--port PORT', Integer,
    '#Port on which service runs. Default: 143.') do |port|
      @options.port = port
    end

    parser.on('-l', '--login LOGIN', String,
    '#Login needed to execute the script.') do ||
      @options. = 
    end

    parser.on('-x', '--password PASSWORD', String,
    '#Password needed to execute script.') do |pass|
      @options.password = pass
    end

    parser.on('-s', '--secure', TrueClass, '#Enable ssl.') do
      @options.ssl = true
    end

    parser.on('-i', '--interval INTERVAL', Integer, "#Interval at which program checks new mail. Default: 30 seconds.") do |interv|
      @options.interval = interv unless interv < 30
    end

    parser.on('-o', '--pop', '#Enables POP3. Default is IMAP.') do
      @options.pop = true
    end

    parser.on('-h', '--help', 'Prints this help.') do
      puts parser
      exit
    end
  end
end

.Parse(args) ⇒ Object



17
18
19
20
21
22
# File 'lib/mailchekka/parser.rb', line 17

def self.Parse(args)
  @options = Options.new
  args << '-h' if args.empty?
  opt_parser.parse!(args)
  @options
end