class Yoptparse::Option
Public Class Methods
new(argument_name:, argument_type:, command_class:)
click to toggle source
@param argument_name [Symbol] @param argument_type [Symbol] @param command_class [Class]
# 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
Public Instance Methods
description()
click to toggle source
@return [String]
# File lib/yoptparse/option.rb, line 13 def description [description_main, description_suffix].compact.join(" ") end
long_option()
click to toggle source
@return [String]
# File lib/yoptparse/option.rb, line 18 def long_option "--#{chain_cased_argument_name}#{long_option_suffix}" end
type_class()
click to toggle source
@return [Class]
# 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
Private Instance Methods
boolean?()
click to toggle source
@return [Boolean]
# File lib/yoptparse/option.rb, line 53 def boolean? if tag tag.type == "Boolean" else false end end
chain_cased_argument_name()
click to toggle source
@return [String]
# File lib/yoptparse/option.rb, line 62 def chain_cased_argument_name @argument_name.to_s.gsub("_", "-") end
description_main()
click to toggle source
@return [String, nil]
# File lib/yoptparse/option.rb, line 67 def description_main if tag tag.text end end
description_suffix()
click to toggle source
@return [String, nil]
# File lib/yoptparse/option.rb, line 74 def description_suffix if required? "(required)" end end
long_option_suffix()
click to toggle source
@return [String, nil]
# File lib/yoptparse/option.rb, line 81 def long_option_suffix unless boolean? "=" end end
required?()
click to toggle source
@return [Boolean]
# File lib/yoptparse/option.rb, line 88 def required? @argument_type == :keyreq end
tag()
click to toggle source
@return [YARD::Tag, nil]
# File lib/yoptparse/option.rb, line 93 def tag ::YARD::Registry.at("#{@command_class}#initialize").tags.find do |tag| tag.tag_name == "param" && tag.name == @argument_name.to_s end end