Class: BankTransactionReference
- Inherits:
-
Object
- Object
- BankTransactionReference
- Defined in:
- app/lib/bank_transaction_reference.rb
Class Method Summary collapse
- .js_code_for_user(user) ⇒ Object
-
.parse(data) ⇒ Object
parses a string from a bank transaction field.
Class Method Details
.js_code_for_user(user) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/lib/bank_transaction_reference.rb', line 19 def self.js_code_for_user(user) %{ function(items) { var ret = "FS#{user.ordergroup.id}.#{user.id}"; for (var key in items) { if (items.hasOwnProperty(key)) { ret += key + items[key]; } } return ret; } } end |
.parse(data) ⇒ Object
parses a string from a bank transaction field
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/lib/bank_transaction_reference.rb', line 3 def self.parse(data) m = /(^|[^\w.])FS(?<group>\d+)(\.(?<user>\d+))?(?<parts>([A-Za-z]+\d+(\.\d+)?)+)([^\w.]|$)/.match(data) return unless m parts = {} m[:parts].scan(/([A-Za-z]+)(\d+(\.\d+)?)/) do |category, value| value = value.to_f value += parts[category] if parts[category] parts[category] = value end ret = { group: m[:group].to_i, parts: parts } ret[:user] = m[:user].to_i if m[:user] ret end |