Class: CommandMapper::Gen::Arg

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

Direct Known Subclasses

Argument, OptionValue

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(required: nil, type: nil) ⇒ Arg

Initializes the parsed argument.

Parameters:

  • required (Boolean, nil) (defaults to: nil)
  • type (Types::Type, nil) (defaults to: nil)


20
21
22
23
# File 'lib/command_mapper/gen/arg.rb', line 20

def initialize(required: nil, type: nil)
  @required = required
  @type     = type
end

Instance Attribute Details

#requiredBoolean (readonly)

Returns:

  • (Boolean)


6
7
8
# File 'lib/command_mapper/gen/arg.rb', line 6

def required
  @required
end

#typeTypes::Type? (readonly)

The value configuration for the argument.

Returns:

  • (Types::Type, nil)


11
12
13
# File 'lib/command_mapper/gen/arg.rb', line 11

def type
  @type
end

Instance Method Details

#to_rubyString

Converts the parsed argument to Ruby source code.

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
# File 'lib/command_mapper/gen/arg.rb', line 30

def to_ruby
  ruby = []
  ruby << "required: #{@required.inspect}" if @required == false

  if (@type && (type = @type.to_ruby))
    ruby << "type: #{type}"
  end

  ruby.join(', ')
end