Class: ShellOpts::Grammar::FloatArgument

Inherits:
ArgumentType show all
Defined in:
lib/shellopts/argument_type.rb

Instance Attribute Summary

Attributes inherited from ArgumentType

#message

Instance Method Summary collapse

Methods inherited from ArgumentType

#name, #to_s

Instance Method Details

#convert(value) ⇒ Object



57
# File 'lib/shellopts/argument_type.rb', line 57

def convert(value) value.to_f end

#match?(name, literal) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/shellopts/argument_type.rb', line 50

def match?(name, literal) 
  # https://stackoverflow.com/a/21891705/2130986
  literal =~ /^[+-]?(?:0|[1-9]\d*)(?:\.(?:\d*[1-9]|0))?$/ or 
      set_message "Illegal decimal value in #{name}: #{literal}"
end

#value?(value) ⇒ Boolean

Returns:

  • (Boolean)


56
# File 'lib/shellopts/argument_type.rb', line 56

def value?(value) value.is_a?(Numeric) end