Class: SVUtils
- Inherits:
-
Object
- Object
- SVUtils
- Defined in:
- lib/SVClient/SVUtils.rb
Constant Summary collapse
- QC_DATE_TIME_FORMAT =
'%d%m%Y%H%M%S'
- QC_DATE_FORMAT =
'%d%m%Y'
Class Method Summary collapse
- .getcurrentdate ⇒ Object
- .getdate(value, format = nil) ⇒ Object
-
.getfloat(value) ⇒ Object
Function to format the currency to standard notation which was received from server’s locale currency format.
- .isnullorempty(value) ⇒ Object
- .parsegiftrecenttransactions(value) ⇒ Object
Class Method Details
.getcurrentdate ⇒ Object
34 35 36 37 |
# File 'lib/SVClient/SVUtils.rb', line 34 def self.getcurrentdate d = DateTime.now return d.strftime(SVUtils::QC_DATE_TIME_FORMAT) end |
.getdate(value, format = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/SVClient/SVUtils.rb', line 24 def self.getdate (value, format = nil) return nil if isnullorempty(value) return nil if isnullorempty(format) begin return DateTime.strptime(value, format) rescue return nil end end |
.getfloat(value) ⇒ Object
Function to format the currency to standard notation which was received from server’s locale currency format.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/SVClient/SVUtils.rb', line 40 def self.getfloat(value) retval = -1 value = (value == nil) ? "" : value.to_s.strip() return -1 if (value.length <= 0) iindex = value.index(/[.]/, 0) if (iindex == nil) return value.gsub(/[^0-9]/, "").to_f else decimalpart = value[iindex + 1, value.length] wholepart = value[0, iindex] ilen = decimalpart.length if( (ilen == 1) || (ilen == 2) || (ilen == 3) ) fullnumber = wholepart.gsub(/[^0-9]/, "") fullnumber = fullnumber + "." + decimalpart else fullnumber = value.gsub(/[^0-9]/, "") end end begin retval = fullnumber.to_f rescue retval = -1 end return retval end |
.isnullorempty(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/SVClient/SVUtils.rb', line 16 def self.isnullorempty (value) return true if (value == nil) value = value.to_s return ((value.strip.length) <= 0) ? true : false end |
.parsegiftrecenttransactions(value) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/SVClient/SVUtils.rb', line 69 def self.parsegiftrecenttransactions(value) arr = Array.new value[0].split(/[{]/n).each do |row| next if (row == nil || row == "") grt = SVGiftRecentTransactions.new row.chomp('}').split(/[|]/).each do |keypaircollection| grt.setvalue(keypaircollection) end arr << grt end return arr end |