Class: DBMapping::RelationsMapper

Inherits:
Base
  • Object
show all
Defined in:
lib/data/sqlite/relations_mapper.rb

Overview

class to apply ER-mapping for person to tasks relations in a sqlite database

Instance Attribute Summary

Attributes inherited from Base

#db_base

Instance Method Summary collapse

Methods inherited from Base

#check_max_id

Constructor Details

#initialize(database) ⇒ RelationsMapper

initialization

Parameters:

  • database (SQLite3::Database)

    a reference of the database



10
11
12
# File 'lib/data/sqlite/relations_mapper.rb', line 10

def initialize(database)
  super(database)
end

Instance Method Details

#generate_person_and_task_relations(relations) ⇒ Object

public method to map available tasks the its corresponding persons

Parameters:

  • relations (Hash)

    the mapping person_id => array of task_ids



16
17
18
19
20
21
22
# File 'lib/data/sqlite/relations_mapper.rb', line 16

def generate_person_and_task_relations(relations)
  relations.each_pair { |person_id, values|
    values.each { |task_id|
      @db_base.map_task_to_person(person_id, task_id)
    }
  }
end

#map_entity_relationsHash

method to retrieve the task assignments to the persons identified by its corresponding ids

Returns:

  • (Hash)

    the mapping person_id => array of task_ids



27
28
29
30
31
32
33
34
# File 'lib/data/sqlite/relations_mapper.rb', line 27

def map_entity_relations
  assignments = @db_base.query_assignments
  results = Hash.new()
  assignments.each { |result|
    results[result["P_Id"]] = result["T_Id"]
  }
  return results
end

#retrieve_tasks_for_person(p_id) ⇒ Array

method to retrieve the task ids assigned to a person represented by its id

Parameters:

  • p_id (Integer)

    the person id

Returns:

  • (Array)

    the task ids



39
40
41
42
43
44
45
46
# File 'lib/data/sqlite/relations_mapper.rb', line 39

def retrieve_tasks_for_person(p_id)
  assignments = @db_base.query_assignments_for_person(p_id)
  results = Array.new()
  assignments.each { |result|
    results << result["T_Id"]
  }
  return results
end