Module: StringToMongo

Defined in:
lib/analyzer.rb

Class Method Summary collapse

Class Method Details

.date?(text_string) ⇒ Boolean

Returns:

  • (Boolean)


317
318
319
320
321
322
323
# File 'lib/analyzer.rb', line 317

def self.date? text_string
  if Chronic.parse(text_string) != nil
    true
  else
    false
  end
end

.float?(text_string) ⇒ Boolean

Returns:

  • (Boolean)


309
310
311
312
313
314
315
# File 'lib/analyzer.rb', line 309

def self.float? text_string
  if text_string.match /^\d*\.\d*$/
    true
  else
    false
  end
end

.integer?(text_string) ⇒ Boolean

Returns:

  • (Boolean)


301
302
303
304
305
306
307
# File 'lib/analyzer.rb', line 301

def self.integer? text_string
  if text_string.match /^\d*$/
    true
  else
    false
  end
end

.mongo_type(text_string) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/analyzer.rb', line 325

def self.mongo_type text_string
  case 
  when nil?(text_string)
    "String"
  when integer?(text_string)
    "Integer"
  when float?(text_string)
    "Float"
  when date?(text_string)
    "Time"
  else
    "String"
    
  end
end

.nil?(text_string) ⇒ Boolean

Returns:

  • (Boolean)


294
295
296
297
298
299
300
# File 'lib/analyzer.rb', line 294

def self.nil? text_string
  if text_string==nil
    true
  else
    false
  end
end