Class: QuickBase::Misc
- Inherits:
-
Object
- Object
- QuickBase::Misc
- Defined in:
- lib/broker/client/QuickBaseMisc.rb
Overview
Miscellaneous static helper methods
Class Method Summary collapse
- .arrayToListUser(array) ⇒ Object
- .createBase32ConversionHash ⇒ Object
- .decimalToBase32(decimalNumber) ⇒ Object
- .isBase32Number?(string) ⇒ Boolean
- .isDbidString?(string) ⇒ Boolean
- .listUserToArray(listUser) ⇒ Object
- .ruby19? ⇒ Boolean
- .save_file(filename, contents, mode = "wb") ⇒ Object
- .time_in_milliseconds(time = nil) ⇒ Object
Class Method Details
.arrayToListUser(array) ⇒ Object
99 100 101 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 99 def Misc.arrayToListUser(array) array.join(";") end |
.createBase32ConversionHash ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 23 def Misc.createBase32ConversionHash base32Symbols = {} decimal = 0 ("a".."z").each{|letter| unless letter == "l" or letter == "o" base32Symbols[decimal.to_s]=letter decimal += 1 end } (2..9).each{|number| base32Symbols[decimal.to_s]=number.to_s decimal += 1 } base32Symbols end |
.decimalToBase32(decimalNumber) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 39 def Misc.decimalToBase32(decimalNumber) @base32Symbols ||= Misc.createBase32ConversionHash base32Num = "" decimalNumber = decimalNumber.to_i if decimalNumber < 32 base32Num = @base32Symbols[decimalNumber.to_s] else power = 10 power -= 1 while (decimalNumber/(32**power)) < 1 while decimalNumber > 0 n = (decimalNumber/(32**power)) base32Num << @base32Symbols[n.to_s] if @base32Symbols[n.to_s] decimalNumber = (decimalNumber-((32**power)*n)) power -= 1 end end base32Num end |
.isBase32Number?(string) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 58 def Misc.isBase32Number?(string) ret = true if string @base32Symbols ||= Misc.createBase32ConversionHash base32SymbolsValues = @base32Symbols.values stringCopy = string.to_s stringCopy.split(//).each{|char| if !base32SymbolsValues.include?(char) ret = false break end } else ret = false end ret end |
.isDbidString?(string) ⇒ Boolean
76 77 78 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 76 def Misc.isDbidString?(string) Misc.isBase32Number?(string) end |
.listUserToArray(listUser) ⇒ Object
95 96 97 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 95 def Misc.listUserToArray(listUser) listUser.split(/;/) end |
.ruby19? ⇒ Boolean
19 20 21 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 19 def Misc.ruby19? RUBY_VERSION >= "1.9" end |
.save_file(filename, contents, mode = "wb") ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 103 def Misc.save_file(filename, contents, mode="wb") File.open(filename, mode){|f| f.write(contents) f.flush } rescue StandardError => error new_filename = filename.gsub(/\W/,"_") File.open(new_filename, mode){|f| f.write(contents) f.flush } end |
.time_in_milliseconds(time = nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/broker/client/QuickBaseMisc.rb', line 80 def Misc.time_in_milliseconds(time = nil) ret = 0 time ||= Time.now if time.is_a?(Time) ret = (time.to_f * 1000).to_i elsif time.is_a?(DateTime) t = Time.mktime(time.year,time.month,time.day,time.hour,time.min,time.sec,0) ret = (t.to_f * 1000).to_i elsif time.is_a?(Date) t = Time.mktime(time.year,time.month,time.day,0,0,0,0) ret = (t.to_f * 1000).to_i end ret end |