Sha256: f9a390569e2072ba79edca67056daf67203e7a9948147d23540cbf1d86350ad2
Contents?: true
Size: 911 Bytes
Versions: 3
Compression:
Stored size: 911 Bytes
Contents
require 'bigdecimal' module Quicken class Transaction < Foundation accessors_for_spec Quicken::Spec::TRANSACTION def initialize(attrs) @date_format = attrs.delete(:date_format) || [:month,:day,:year] super(attrs) end def date=(value) parts = extract_date_parts(value) @date = Date.parse("#{parts[:year]}-#{parts[:month]}-#{parts[:day]}", true) end %w(amount investment_price investment_shares_quantity investment_commission split_or_investment_amount).each do |method| define_method "#{method}=" do |value| instance_variable_set("@#{method}", BigDecimal.new(value.delete(","))) end end private def extract_date_parts(date) parts = date.match(/(\d+)[\/|\-](\d+)[\/|\-|'](\d+)/)[1..3] result = {} @date_format.each_with_index { |v, i| result.merge!({ v => parts[i] }) } result end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
quicken-0.0.3 | lib/quicken/transaction.rb |
quicken-0.0.2 | lib/quicken/transaction.rb |
quicken-0.0.1 | lib/quicken/transaction.rb |