Class: ConceptQL::Behaviors::Debuggable::ResultPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/conceptql/behaviors/debuggable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db, dir, type, watch_ids, operator) ⇒ ResultPrinter

Returns a new instance of ResultPrinter.



11
12
13
14
15
16
17
# File 'lib/conceptql/behaviors/debuggable.rb', line 11

def initialize(db, dir, type, watch_ids, operator)
  @db = db
  @dir = dir
  @type = type
  @watch_ids = watch_ids
  @operator = operator
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



10
11
12
# File 'lib/conceptql/behaviors/debuggable.rb', line 10

def db
  @db
end

#dirObject (readonly)

Returns the value of attribute dir.



10
11
12
# File 'lib/conceptql/behaviors/debuggable.rb', line 10

def dir
  @dir
end

#operatorObject (readonly)

Returns the value of attribute operator.



10
11
12
# File 'lib/conceptql/behaviors/debuggable.rb', line 10

def operator
  @operator
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/conceptql/behaviors/debuggable.rb', line 10

def type
  @type
end

#watch_idsObject (readonly)

Returns the value of attribute watch_ids.



10
11
12
# File 'lib/conceptql/behaviors/debuggable.rb', line 10

def watch_ids
  @watch_ids
end

Instance Method Details

#abbreviate(type) ⇒ Object



49
50
51
# File 'lib/conceptql/behaviors/debuggable.rb', line 49

def abbreviate(type)
  type.to_s.split('_').map(&:chars).map(&:first).join('')
end

#file_nameObject



33
34
35
# File 'lib/conceptql/behaviors/debuggable.rb', line 33

def file_name
  @file_name ||= [operator.operator_name, abbreviate(type)].join('_')
end

#file_pathObject



29
30
31
# File 'lib/conceptql/behaviors/debuggable.rb', line 29

def file_path
  @file_path ||= dir + file_name
end

#make_fileObject



19
20
21
22
23
24
25
26
27
# File 'lib/conceptql/behaviors/debuggable.rb', line 19

def make_file
  CSV.open(file_path, 'w') do |csv|
    csv << ConceptQL::Operators::Operator::COLUMNS
    results.each do |result|
      csv << result
    end
  end
  file_path
end

#resultsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/conceptql/behaviors/debuggable.rb', line 37

def results
  q = operator.evaluate(db)
    .from_self
    .where(criterion_type: type.to_s)
  unless watch_ids.empty?
    q = q.where(person_id: watch_ids)
  end

  q.order([:person_id, :criterion_type, :start_date, :end_date, :criterion_id])
    .select_map(ConceptQL::Operators::Operator::COLUMNS)
end