Sha256: ea02b3b387de425ded7724bd4c51506ff140fb3cc9de647e73311b6594b42926

Contents?: true

Size: 954 Bytes

Versions: 1

Compression:

Stored size: 954 Bytes

Contents

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
      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

    def self.to_a
      options = @@options
      @@options = {}
      all.select { |bank| options.map { |k, v| bank.send(k) == v }.all? }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
banking_data-0.3.0 lib/banking_data/bank.rb