Class: Perus::Pinger::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/perus/pinger/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, settings, command) ⇒ Option

Returns a new instance of Option.



8
9
10
11
12
13
# File 'lib/perus/pinger/command.rb', line 8

def initialize(name, settings, command)
    @name = name
    @command = command
    @default = settings[:default]
    @restricted = settings[:restricted] == true
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



6
7
8
# File 'lib/perus/pinger/command.rb', line 6

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/perus/pinger/command.rb', line 6

def name
  @name
end

#restrictedObject (readonly)

Returns the value of attribute restricted.



6
7
8
# File 'lib/perus/pinger/command.rb', line 6

def restricted
  @restricted
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/perus/pinger/command.rb', line 15

def boolean?
    default.is_a?(TrueClass) || default.is_a?(FalseClass)
end

#process(results, values) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/perus/pinger/command.rb', line 19

def process(results, values)
    value = values[name.to_s]
    value = value || default

    if value.nil?
        raise "#{name} is a required option"
    end

    if restricted
        allowed = Pinger.options[@command.name.demodulize][@name.to_s]
        raise "the value, #{value}, passed to #{@name} is not allowed" unless allowed.include?(value)
    end

    results[name] = value
end