Class: Integer

Inherits:
Object show all
Defined in:
lib/user_input.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_user_input(value) ⇒ Object

All characters must be numbers, except for the first which may be -



72
73
74
75
76
77
78
# File 'lib/user_input.rb', line 72

def Integer.from_user_input(value)
	if (value.kind_of?(Integer) || /^\s*-?[0-9]+\s*$/ =~ value.to_s)
		return value.to_i
	else
		return nil
	end
end

Instance Method Details

#from_user_input(value) ⇒ Object

instance form does a straight comparison of value.to_i with self.



81
82
83
84
85
86
87
# File 'lib/user_input.rb', line 81

def from_user_input(value)
	if (!value.kind_of?(Float) && self == value.to_i)
		return value.to_i
	else
		return nil
	end
end