Class: ConceptQL::Behaviors::Debuggable::ResultPrinter
- Inherits:
-
Object
- Object
- ConceptQL::Behaviors::Debuggable::ResultPrinter
- Defined in:
- lib/conceptql/behaviors/debuggable.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#watch_ids ⇒ Object
readonly
Returns the value of attribute watch_ids.
Instance Method Summary collapse
- #abbreviate(type) ⇒ Object
- #file_name ⇒ Object
- #file_path ⇒ Object
-
#initialize(db, dir, type, watch_ids, operator) ⇒ ResultPrinter
constructor
A new instance of ResultPrinter.
- #make_file ⇒ Object
- #results ⇒ Object
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
#db ⇒ Object (readonly)
Returns the value of attribute db.
10 11 12 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 10 def db @db end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
10 11 12 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 10 def dir @dir end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
10 11 12 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 10 def operator @operator end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 10 def type @type end |
#watch_ids ⇒ Object (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_name ⇒ Object
33 34 35 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 33 def file_name @file_name ||= [operator.operator_name, abbreviate(type)].join('_') end |
#file_path ⇒ Object
29 30 31 |
# File 'lib/conceptql/behaviors/debuggable.rb', line 29 def file_path @file_path ||= dir + file_name end |
#make_file ⇒ Object
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 |
#results ⇒ Object
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 |