Class: CommandMapper::Gen::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/command_mapper/gen/option.rb

Overview

Represents a mock CommandMapper::Option class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flag, equals: nil, repeats: nil, value: nil) ⇒ Option

Initializes the parsed argument.

Parameters:

  • flag (String) —

    The option flag.

  • equals (Boolean, :optional, nil) (defaults to: nil)
  • repeats (Boolean, nil) (defaults to: nil)
  • value (Hash{Symbol => Object}, nil) (defaults to: nil)


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)

Returns:

  • (Boolean, :equals, nil)


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.

Returns:

  • (String)


13
14
15
# File 'lib/command_mapper/gen/option.rb', line 13

def flag
  @flag
end

#repeats ⇒ Boolean? (readonly)

Returns:

  • (Boolean, nil)


19
20
21
# File 'lib/command_mapper/gen/option.rb', line 19

def repeats
  @repeats
end

#value ⇒ OptionValue? (readonly)

Returns:



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.

Returns:

  • (String)


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