Class: Icemaker::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/icemaker/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

Returns a new instance of Query.



33
34
35
# File 'lib/icemaker/query.rb', line 33

def initialize(params)
  @filters = params[:with]
end

Instance Method Details

#find(params) ⇒ Object

TODO: THE NAMING/LANGUAGE IN THIS CLASS IS TEH SUCK



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/icemaker/query.rb', line 7

def find(params)

  tracks = params[:in]

  @filters.each { |expr|

    tag = expr.keys[0]
    value_to_test = expr.values[0].values[0]
    operator = expr.values[0].keys[0]

    filter = Filter.new tag, value_to_test, operator

    tracks = tracks.select {

      |track|

      filter.tag_value = track[tag.to_sym]

      filter.pass?
    }
  }

  tracks

end