Class: SepaClearer::Clearer
- Inherits:
-
Object
- Object
- SepaClearer::Clearer
- Defined in:
- lib/sepa_clearer/clearer.rb
Constant Summary collapse
- ATTRIBUTES =
Make sure we always have the correct order of columns
[:name, :bic, :sct, :core, :cor1, :b2b]
Instance Attribute Summary collapse
-
#db ⇒ Object
Returns the value of attribute db.
Instance Method Summary collapse
- #add(provider) ⇒ Object
- #all ⇒ Object
- #delete ⇒ Object
- #find_by_bic(bic) ⇒ Object
-
#initialize(db_name = 'deutsche_bundesbank') ⇒ Clearer
constructor
A new instance of Clearer.
- #normalize_bic(bic) ⇒ Object
Constructor Details
#initialize(db_name = 'deutsche_bundesbank') ⇒ Clearer
Returns a new instance of Clearer.
10 11 12 |
# File 'lib/sepa_clearer/clearer.rb', line 10 def initialize(db_name = 'deutsche_bundesbank') self.db = SQLite3::Database.new File.join(File.dirname(__FILE__), '../..', "data/#{db_name}.db") end |
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
5 6 7 |
# File 'lib/sepa_clearer/clearer.rb', line 5 def db @db end |
Instance Method Details
#add(provider) ⇒ Object
14 15 16 17 |
# File 'lib/sepa_clearer/clearer.rb', line 14 def add(provider) data = boolean_to_integers(provider.to_a) db.execute "INSERT INTO payment_providers (#{ATTRIBUTES.join(',')}) VALUES (?, ?, ?, ?, ?, ?)", data end |
#all ⇒ Object
19 20 21 22 23 |
# File 'lib/sepa_clearer/clearer.rb', line 19 def all db.execute("SELECT #{ATTRIBUTES.join(',')} FROM payment_providers ORDER BY name").map do |row| PaymentProvider.new(hash_from_result(row)) end end |
#delete ⇒ Object
31 32 33 |
# File 'lib/sepa_clearer/clearer.rb', line 31 def delete db.execute("DELETE FROM payment_providers").first end |
#find_by_bic(bic) ⇒ Object
25 26 27 28 29 |
# File 'lib/sepa_clearer/clearer.rb', line 25 def find_by_bic(bic) db.execute("SELECT #{ATTRIBUTES.join(',')} FROM payment_providers WHERE bic = ?", normalize_bic(bic)).map do |row| PaymentProvider.new(hash_from_result(row)) end.first end |
#normalize_bic(bic) ⇒ Object
35 36 37 |
# File 'lib/sepa_clearer/clearer.rb', line 35 def normalize_bic(bic) bic.to_s.ljust(11, 'X').upcase end |