Class: CommandMapper::Gen::Option
- Inherits:
-
Object
- Object
- CommandMapper::Gen::Option
- Defined in:
- lib/command_mapper/gen/option.rb
Overview
Represents a mock CommandMapper::Option
class.
Instance Attribute Summary collapse
- #equals ⇒ Boolean, ... readonly
-
#flag ⇒ String
readonly
The option flag for the option.
- #repeats ⇒ Boolean? readonly
- #value ⇒ OptionValue? readonly
Instance Method Summary collapse
-
#initialize(flag, equals: nil, repeats: nil, value: nil) ⇒ Option
constructor
Initializes the parsed argument.
-
#to_ruby ⇒ String
Converts the parsed option to Ruby source code.
Constructor Details
#initialize(flag, equals: nil, repeats: nil, value: nil) ⇒ Option
Initializes the parsed argument.
36 37 38 39 40 41 |
# File 'lib/command_mapper/gen/option.rb', line 36 def initialize(flag, equals: nil, repeats: nil, value: nil) @flag = flag @equals = equals @value = OptionValue.new(**value) if value @repeats = repeats end |
Instance Attribute Details
#equals ⇒ Boolean, ... (readonly)
16 17 18 |
# File 'lib/command_mapper/gen/option.rb', line 16 def equals @equals end |
#flag ⇒ String (readonly)
The option flag for the option.
13 14 15 |
# File 'lib/command_mapper/gen/option.rb', line 13 def flag @flag end |
#repeats ⇒ Boolean? (readonly)
19 20 21 |
# File 'lib/command_mapper/gen/option.rb', line 19 def repeats @repeats end |
#value ⇒ OptionValue? (readonly)
22 23 24 |
# File 'lib/command_mapper/gen/option.rb', line 22 def value @value end |
Instance Method Details
#to_ruby ⇒ String
Converts the parsed option to Ruby source code.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/command_mapper/gen/option.rb', line 48 def to_ruby ruby = "option #{@flag.inspect}" fixme = nil if @flag =~ /^-[a-zA-Z0-9]/ && @flag.length <= 3 ruby << ", name: " fixme = "name" end ruby << ", equals: #{@equals.inspect}" unless @equals.nil? ruby << ", repeats: #{@repeats.inspect}" unless @repeats.nil? ruby << ", value: #{@value.to_ruby}" if @value ruby << "\t# FIXME: #{fixme}" if fixme ruby end |