Class: Banker::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agent=(value) ⇒ Object (writeonly)

Sets the attribute agent

Parameters:

  • value

    the value to set the attribute agent to.



3
4
5
# File 'lib/banker/base.rb', line 3

def agent=(value)
  @agent = value
end

#keys=(value) ⇒ Object (writeonly)

Sets the attribute keys

Parameters:

  • value

    the value to set the attribute keys to.



3
4
5
# File 'lib/banker/base.rb', line 3

def keys=(value)
  @keys = value
end

Instance Method Details

#class_nameObject



25
26
27
# File 'lib/banker/base.rb', line 25

def class_name
  self.class.name.split("::").last
end

#cleaner(str) ⇒ Object



37
38
39
# File 'lib/banker/base.rb', line 37

def cleaner(str)
  str.gsub(/[^\d+]/, '')
end

#get(url) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/banker/base.rb', line 16

def get(url)
  @agent ||= Mechanize.new
  @agent.log = Logger.new 'banker.log'
  @agent.user_agent = "Mozilla/5.0 (Banker)"
  @agent.force_default_encoding = "utf8"
  @agent.agent.http.ssl_version = :SSLv3
  @agent.get(url)
end

#get_letter(value, index) ⇒ Object



29
30
31
# File 'lib/banker/base.rb', line 29

def get_letter(value,index)
  value.to_s[index-1]
end

#memorable_required(page) ⇒ Object



33
34
35
# File 'lib/banker/base.rb', line 33

def memorable_required(page)
  page.labels.collect { |char| cleaner(char.to_s).to_i }
end

#params(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/banker/base.rb', line 4

def params(args)
  missing_keys = []
  return unless defined? @keys
  @keys.each do |key|
    missing_keys << key unless args.has_key?(key.to_sym)
  end
  if missing_keys.any?
    raise Error::InvalidParams,
      "missing parameters #{missing_keys.map {|key| "`#{key}` "}.join}"
  end
end

#parse_ofx(type = 'bank_account') ⇒ Object



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/banker/base.rb', line 41

def parse_ofx(type='bank_account')
  if type == 'credit_card'
    _accounts = ofx.credit_cards
  elsif type == 'bank_account'
    _accounts = ofx.bank_accounts
  end
  _accounts.each_with_object(@accounts) do |, accounts|
    args = { uid: Digest::MD5.hexdigest("#{class_name}#{@membership_number}#{.id}"),
             name: "#{class_name} #{.id[-4..-1]}",
             amount: .balance.amount_in_pennies,
             currency: .currency }
     = Banker::Account.new(args)
    .transactions.each do |transaction|
      transaction_args = {
        :amount => transaction.amount_in_pennies,
        :description => transaction.name,
        :transacted_at => transaction.posted_at,
        :uid => transaction.fit_id,
        :type => transaction.type
      }
      e_transaction = Banker::Transaction.new(transaction_args)
      .transactions << e_transaction
    end
    .transactions.sort_by {|k,v| k.transacted_at}.reverse
    accounts << 
  end
end