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.
9 10 11 12 13 |
# File 'lib/banking_data/query.rb', line 9 def initialize(, only = nil) @locale = .delete(:locale) @options = @attributes = only end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/banking_data/query.rb', line 7 def attributes @attributes end |
#locale ⇒ Object
Returns the value of attribute locale.
7 8 9 |
# File 'lib/banking_data/query.rb', line 7 def locale @locale end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/banking_data/query.rb', line 7 def @options end |
Instance Method Details
#bank ⇒ Object
38 39 40 |
# File 'lib/banking_data/query.rb', line 38 def bank Bank.subclasses.find { |bank_class| bank_class::LOCALE == locale } end |
#only(*attrs) ⇒ Object
22 23 24 25 26 |
# File 'lib/banking_data/query.rb', line 22 def only(*attrs) clone.tap do |query| query.attributes = attrs end end |
#to_a ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/banking_data/query.rb', line 28 def to_a 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 = {}) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/banking_data/query.rb', line 15 def where(opts = {}) clone.tap do |query| query.locale = opts.delete(:locale) query. = @options.merge(opts) end end |