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



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

def convert(value) value.to_f end

#match?(name, literal) ⇒ Boolean



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

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



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

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