Class: MotionCSV::NumericConversion
- Defined in:
- lib/motion-csv/motion-csv.rb
Instance Method Summary collapse
- #<<(ch) ⇒ Object
- #clear ⇒ Object
- #convert(as_string = false) ⇒ Object
-
#initialize ⇒ NumericConversion
constructor
A new instance of NumericConversion.
Methods inherited from Array
Constructor Details
#initialize ⇒ NumericConversion
Returns a new instance of NumericConversion.
216 217 218 219 |
# File 'lib/motion-csv/motion-csv.rb', line 216 def initialize @int = @float = true @dot = false end |
Instance Method Details
#<<(ch) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/motion-csv/motion-csv.rb', line 227 def <<(ch) if ch == ?-.ord @float = @int = size == 0 elsif (ch > ?9.ord || ch < ?0.ord) && ch != ?..ord @int = @float = false elsif ch == ?..ord && @dot @int = @float = false elsif ch == ?..ord @int = false @dot = true end super(ch.chr) end |
#clear ⇒ Object
221 222 223 224 225 |
# File 'lib/motion-csv/motion-csv.rb', line 221 def clear @int = @float = true @dot = false super end |
#convert(as_string = false) ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/motion-csv/motion-csv.rb', line 242 def convert(as_string = false) if as_string join elsif empty? nil elsif @int join.to_i elsif @float join.to_f else join end end |