Class: CsvRecord::Query
- Includes:
- Enumerable
- Defined in:
- lib/csv_record/csv_queries/query.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #__to_a__ ⇒ Object (also: #to_a)
- #__trigger__ ⇒ Object (also: #trigger)
- #__where__(params) ⇒ Object (also: #where)
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(klass, conditions) ⇒ Query
constructor
A new instance of Query.
- #inspect ⇒ Object
- #last ⇒ Object
Constructor Details
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
6 7 8 |
# File 'lib/csv_record/csv_queries/query.rb', line 6 def conditions @conditions end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/csv_record/csv_queries/query.rb', line 6 def klass @klass end |
Instance Method Details
#__to_a__ ⇒ Object Also known as: to_a
33 34 35 |
# File 'lib/csv_record/csv_queries/query.rb', line 33 def __to_a__ trigger end |
#__trigger__ ⇒ Object Also known as: trigger
22 23 24 25 26 27 |
# File 'lib/csv_record/csv_queries/query.rb', line 22 def __trigger__ klass.open_database_file do |csv| rows = search_for csv, self.conditions rows.map { |row| klass.build row.to_hash } end end |
#__where__(params) ⇒ Object Also known as: where
16 17 18 19 20 |
# File 'lib/csv_record/csv_queries/query.rb', line 16 def __where__(params) new_conditions = (CsvRecord::Condition.create_from_hashes params) @conditions = (@conditions << new_conditions).flatten # figure out a way to solve this later self end |
#each(&block) ⇒ Object
41 42 43 |
# File 'lib/csv_record/csv_queries/query.rb', line 41 def each(&block) to_a.each &block end |
#empty? ⇒ Boolean
45 46 47 |
# File 'lib/csv_record/csv_queries/query.rb', line 45 def empty? to_a.empty? end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/csv_record/csv_queries/query.rb', line 29 def inspect to_a.inspect end |
#last ⇒ Object
37 38 39 |
# File 'lib/csv_record/csv_queries/query.rb', line 37 def last to_a.last end |