Class: BankingData::Query
- Inherits:
-
Object
- Object
- BankingData::Query
- Defined in:
- lib/banking_data/query.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #bank ⇒ Object
-
#initialize(options, only = nil) ⇒ Query
constructor
A new instance of Query.
- #only(*attrs) ⇒ Object
- #to_a ⇒ Object
- #where(opts = {}) ⇒ Object
Constructor Details
#initialize(options, only = nil) ⇒ Query
Returns a new instance of Query.
10 11 12 13 14 |
# File 'lib/banking_data/query.rb', line 10 def initialize(, only = nil) @locale = .delete(:locale) = @attributes = only end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/banking_data/query.rb', line 8 def attributes @attributes end |
#locale ⇒ Object
Returns the value of attribute locale.
8 9 10 |
# File 'lib/banking_data/query.rb', line 8 def locale @locale end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/banking_data/query.rb', line 8 def end |
Instance Method Details
#bank ⇒ Object
41 42 43 |
# File 'lib/banking_data/query.rb', line 41 def bank Bank.subclasses.find { |bank_class| bank_class::LOCALE == locale } end |
#only(*attrs) ⇒ Object
23 24 25 26 27 |
# File 'lib/banking_data/query.rb', line 23 def only(*attrs) clone.tap do |query| query.attributes = attrs end end |
#to_a ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/banking_data/query.rb', line 29 def to_a return [] if bank.nil? data = bank.all .select { |bank| .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 = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/banking_data/query.rb', line 16 def where(opts = {}) clone.tap do |query| query.locale = opts.delete(:locale) query. = .merge(opts) end end |