Class: CommandMapper::Gen::Argument

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

Overview

Represents a mock CommandMapper::Argument class.

Instance Attribute Summary collapse

Attributes inherited from Arg

#required, #type

Instance Method Summary collapse

Constructor Details

#initialize(name, repeats: nil, **kwargs) ⇒ Argument

Initializes the parsed argument.

Parameters:

  • name (Symbol)

    The argument name.

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

    Additional keyword arguments.



29
30
31
32
33
34
# File 'lib/command_mapper/gen/argument.rb', line 29

def initialize(name, repeats: nil, **kwargs)
  super(**kwargs)

  @name    = name
  @repeats = repeats
end

Instance Attribute Details

#nameSymbol (readonly)

The name of the argument.

Returns:

  • (Symbol)


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

def name
  @name
end

#repeatsBoolean? (readonly)

Returns:

  • (Boolean, nil)


16
17
18
# File 'lib/command_mapper/gen/argument.rb', line 16

def repeats
  @repeats
end

Instance Method Details

#to_rubyString

Converts the parsed argument to Ruby source code.

Returns:

  • (String)


41
42
43
44
45
46
47
48
49
# File 'lib/command_mapper/gen/argument.rb', line 41

def to_ruby
  ruby = "argument #{@name.inspect}"

  keywords = super()
  ruby << ", #{keywords}" unless keywords.empty?

  ruby << ", repeats: #{@repeats.inspect}" unless @repeats.nil?
  ruby
end