Class: FastererCSV::NumericConversion

Inherits:
Array
  • Object
show all
Defined in:
lib/fasterer_csv.rb

Instance Method Summary collapse

Constructor Details

#initializeNumericConversion

Returns a new instance of NumericConversion.



212
213
214
215
# File 'lib/fasterer_csv.rb', line 212

def initialize
  @int = @float = true
  @dot = false
end

Instance Method Details

#<<(ch) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/fasterer_csv.rb', line 223

def <<(ch)
  if ch == ?-
    @float = @int = size == 0
  elsif (ch > ?9 || ch < ?0) && ch != ?.
    @int = @float = false
  elsif ch == ?. && @dot
    @int = @float = false
  elsif ch == ?.
    @int = false
    @dot = true
  end

  super(ch.chr)
end

#clearObject



217
218
219
220
221
# File 'lib/fasterer_csv.rb', line 217

def clear
  @int = @float = true
  @dot = false
  super
end

#convert(as_string = false) ⇒ Object



238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/fasterer_csv.rb', line 238

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