Class: Yoptparse::Option

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

Instance Method Summary collapse

Constructor Details

#initialize(argument_name:, argument_type:, command_class:) ⇒ Option

Returns a new instance of Option.

Parameters:

  • argument_name (Symbol)
  • argument_type (Symbol)
  • command_class (Class)


6
7
8
9
10
# File 'lib/yoptparse/option.rb', line 6

def initialize(argument_name:, argument_type:, command_class:)
  @argument_name = argument_name
  @argument_type = argument_type
  @command_class = command_class
end

Instance Method Details

#descriptionString

Returns:

  • (String)


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

def description
  [description_main, description_suffix].compact.join(" ")
end

#long_optionString

Returns:

  • (String)


18
19
20
# File 'lib/yoptparse/option.rb', line 18

def long_option
  "--#{chain_cased_argument_name}#{long_option_suffix}"
end

#type_classClass

Returns:

  • (Class)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/yoptparse/option.rb', line 23

def type_class
  if tag
    case tag.type
    when "Array"
      ::Array
    when "Float"
      ::Float
    when "Integer"
      ::Integer
    when "Numeric"
      ::Numeric
    when "OptionParser::DecimalInteger"
      ::OptionParser::DecimalInteger
    when "OptionParser::DecimalNumeric"
      ::OptionParser::DecimalNumeric
    when "OptionParser::OctalInteger"
      ::OptionParser::OctalInteger
    when "String"
      ::String
    else
      ::Object
    end
  else
    ::Object
  end
end