Class: Wpxf::StringOption
- Defined in:
- lib/wpxf/core/opts/string_option.rb
Overview
A string option.
Instance Attribute Summary
Attributes inherited from Option
#advanced, #default, #desc, #enums, #evasion, #name, #regex, #required
Instance Method Summary collapse
-
#normalize(value) ⇒ String
A normalized value to conform with the type that the option is conveying.
-
#valid?(value) ⇒ Boolean
Check if the specified value is valid in the context of this option.
Methods inherited from Option
#advanced?, #display_value, #empty?, #empty_required_value?, #evasion?, #initialize, #required?, #update_optional_attributes, #value?
Constructor Details
This class inherits a constructor from Wpxf::Option
Instance Method Details
#normalize(value) ⇒ String
Returns a normalized value to conform with the type that the option is conveying.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/wpxf/core/opts/string_option.rb', line 11 def normalize(value) match = value&.match(/^file:(.*)/) if match path = match[1] begin value = File.read(path) rescue ::Errno::ENOENT, ::Errno::EISDIR value = nil end end value end |
#valid?(value) ⇒ Boolean
Check if the specified value is valid in the context of this option.
28 29 30 31 |
# File 'lib/wpxf/core/opts/string_option.rb', line 28 def valid?(value) value = normalize(value) super(value) end |