Class: Daru::WhichQuery

Inherits:
Object show all
Defined in:
lib/daru/extensions/which_dsl.rb

Defined Under Namespace

Classes: VectorWrapper

Instance Method Summary collapse

Constructor Details

#initialize(df, &condition) ⇒ WhichQuery

Returns a new instance of WhichQuery.



21
22
23
24
# File 'lib/daru/extensions/which_dsl.rb', line 21

def initialize(df, &condition)
  @df = df
  @condition = condition
end

Instance Method Details

#`(vector_name) ⇒ Object



32
33
34
35
36
37
# File 'lib/daru/extensions/which_dsl.rb', line 32

def `(vector_name)
  if !@df.has_vector?(vector_name) && @df.has_vector?(vector_name.to_sym)
    vector_name = vector_name.to_sym
  end
  VectorWrapper.new(@df[vector_name])
end

#execObject

executes a block of DSL code



27
28
29
30
# File 'lib/daru/extensions/which_dsl.rb', line 27

def exec
  query = instance_eval(&@condition)
  @df.where(query)
end