Class: Perus::Pinger::Option
- Inherits:
-
Object
- Object
- Perus::Pinger::Option
- Defined in:
- lib/perus/pinger/command.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#restricted ⇒ Object
readonly
Returns the value of attribute restricted.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
-
#initialize(name, settings, command) ⇒ Option
constructor
A new instance of Option.
- #process(results, values) ⇒ Object
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/perus/pinger/command.rb', line 6 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/perus/pinger/command.rb', line 6 def name @name end |
#restricted ⇒ Object (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
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.[@command.name.demodulize][@name.to_s] raise "the value passed to #{@name} is not allowed" unless allowed.include?(value) end results[name] = value end |