Class: Dredd::Query
- Inherits:
-
Object
- Object
- Dredd::Query
- Defined in:
- lib/dredd/query.rb
Instance Attribute Summary collapse
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #all(&block) ⇒ Object
- #execute(collection) ⇒ Object
- #first(num, &block) ⇒ Object
-
#initialize(text) ⇒ Query
constructor
A new instance of Query.
- #last(num, &block) ⇒ Object
Constructor Details
#initialize(text) ⇒ Query
Returns a new instance of Query.
8 9 10 |
# File 'lib/dredd/query.rb', line 8 def initialize(text) instance_eval(text) end |
Instance Attribute Details
#window ⇒ Object (readonly)
Returns the value of attribute window.
6 7 8 |
# File 'lib/dredd/query.rb', line 6 def window @window end |
Instance Method Details
#all(&block) ⇒ Object
12 13 14 15 16 |
# File 'lib/dredd/query.rb', line 12 def all(&block) @window = [:to_a] @filter = block @aggregate = Dsl::Aggregate.new end |
#execute(collection) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/dredd/query.rb', line 30 def execute(collection) slice = collection.send(*@window) .map{|k| Hashie::Mash.new(k)} .select{|k| @filter ? k.instance_eval(&@filter) : true } .map{|k| k.to_hash } @aggregate.execute(slice) end |