lib/banking_data/bank.rb in banking_data-0.3.0 vs lib/banking_data/bank.rb in banking_data-0.4.0
- old
+ new
@@ -1,37 +1,21 @@
module BankingData
class Bank
- @@options = {}
-
- # goal: do something like:
- # BankingData::Bank.where(locale: :de).only(:bic)
- def self.where(options = {})
- locale = options.delete(:locale)
- if locale == 'DE' || locale == :de
- GermanBank.where(options)
- elsif locale == 'AT' || locale == :at
- AustrianBank.where(options)
- elsif locale == 'CH' || locale == :ch
- SwissBank.where(options)
- elsif options.empty?
- self
- else
- @@options = @@options.merge(options)
- self
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
end
end
- def self.only(*attributes)
- options = @@options
- @@options = {}
- all.select { |bank| options.map { |k, v| bank.send(k) == v }.all? }
- .map { |bank| attributes.map { |attr| bank.send(attr) } }
- end
+ class << self
- def self.to_a
- options = @@options
- @@options = {}
- all.select { |bank| options.map { |k, v| bank.send(k) == v }.all? }
+ def where(options)
+ Query.new(options)
+ end
+
+ def query
+ Query.new(locale: self::LOCALE)
+ end
end
end
end