class BankingData::Query
Attributes
attributes[RW]
locale[RW]
options[RW]
Public Class Methods
new(options, only = nil)
click to toggle source
# File lib/banking_data/query.rb, line 10 def initialize(options, only = nil) @locale = options.delete(:locale) @options = options @attributes = only end
Public Instance Methods
bank()
click to toggle source
# File lib/banking_data/query.rb, line 41 def bank Bank.subclasses.find { |bank_class| bank_class::LOCALE == locale } end
only(*attrs)
click to toggle source
# File lib/banking_data/query.rb, line 23 def only(*attrs) clone.tap do |query| query.attributes = attrs end end
to_a()
click to toggle source
# File lib/banking_data/query.rb, line 29 def to_a return [] if bank.nil? data = bank.all .select { |bank| @options.map { |k, v| bank.send(k) == v }.all? } if @attributes data.map { |bank| @attributes.map { |attr| bank.send(attr) } } else data end end
where(opts = {})
click to toggle source
# File lib/banking_data/query.rb, line 16 def where(opts = {}) clone.tap do |query| query.locale = opts.delete(:locale) query.options = @options.merge(opts) end end