Class: String

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

Overview

Overload the class string to convert monetdb to ruby types.

Instance Method Summary collapse

Instance Method Details

#getBlobObject



402
403
404
405
406
407
408
409
410
# File 'lib/MonetDBData.rb', line 402

def getBlob
  # first strip trailing and leading " characters 
  self.gsub(/^"/,'').gsub(/"$/,'')
  
  # convert from HEX to the origianl binary data.
  blob = ""
  self.scan(/../) { |tuple| blob += tuple.hex.chr }
  return blob
end

#getBoolObject



442
443
444
445
446
447
448
449
450
451
# File 'lib/MonetDBData.rb', line 442

def getBool
    if ['1', 'y', 't', 'true'].include?(self)
      return true
    elsif ['0','n','f', 'false'].include?(self)
      return false
    else 
      # unknown
      return nil
    end
end

#getCharObject



431
432
433
434
435
436
437
438
439
440
# File 'lib/MonetDBData.rb', line 431

def getChar
  # ruby < 1.9 does not have a Char datatype
  begin
    c = self.ord
  rescue
    c = self
  end
  
  return c 
end

#getDateObject



419
420
421
# File 'lib/MonetDBData.rb', line 419

def getDate
  self.gsub(/^"/,'').gsub(/"$/,'')
end

#getDateTimeObject



423
424
425
426
427
428
429
# File 'lib/MonetDBData.rb', line 423

def getDateTime
  #YYYY-MM-DD HH:MM:SS
  date = self.split(' ')[0].split('-')
  time = self.split(' ')[1].split(':')
  
  Time.gm(date[0], date[1], date[2], time[0], time[1], time[2])
end

#getFloatObject



378
379
380
# File 'lib/MonetDBData.rb', line 378

def getFloat
  self.to_f
end

#getIntObject



374
375
376
# File 'lib/MonetDBData.rb', line 374

def getInt
  self.to_i
end

#getNullObject



453
454
455
456
457
458
459
# File 'lib/MonetDBData.rb', line 453

def getNull
  if self.upcase == 'NONE'
    return nil
  else
    raise "Unknown value"
  end
end

#getStringObject



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/MonetDBData.rb', line 382

def getString
  #data = self.reverse
  # parse the string starting from the end; 
  #escape = false
  #position = 0
  #for i in data
  #  if i == '\\' and escape == true
  #      if data[position+1] == '\\' 
  #      data[position+1] = ''
  #      escape = true
  #    else
  #      escape = false
  #    end
  #  end
  #  position += 1
  #end
  #data.reverse
  self.gsub(/^"/,'').gsub(/"$/,'')
end

#getTimeObject

ruby currently supports only time + date frommatted timestamps; treat TIME and DATE as strings.



414
415
416
417
# File 'lib/MonetDBData.rb', line 414

def getTime
  # HH:MM:SS
  self.gsub(/^"/,'').gsub(/"$/,'')
end