Class: FastererCSV::NumericConversion
- Inherits:
-
Array
- Object
- Array
- FastererCSV::NumericConversion
- Defined in:
- lib/fasterer_csv.rb
Instance Method Summary collapse
- #<<(ch) ⇒ Object
- #clear ⇒ Object
- #convert(as_string = false) ⇒ Object
-
#initialize ⇒ NumericConversion
constructor
A new instance of NumericConversion.
Constructor Details
#initialize ⇒ NumericConversion
Returns a new instance of NumericConversion.
219 220 221 222 |
# File 'lib/fasterer_csv.rb', line 219 def initialize @int = @float = true @dot = false end |
Instance Method Details
#<<(ch) ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/fasterer_csv.rb', line 230 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
224 225 226 227 228 |
# File 'lib/fasterer_csv.rb', line 224 def clear @int = @float = true @dot = false super end |
#convert(as_string = false) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/fasterer_csv.rb', line 245 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 |