Class: DBMapping::TaskMapper
- Defined in:
- lib/data/sqlite/task_mapper.rb
Overview
class to apply ER-mapping for Task::Task objects to a sqlite database
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create_task_from_result(result) ⇒ Object
private
method to create a Task::Task from a result entry.
-
#generate_tasks ⇒ Array
public method to transform database persons to entity Task::Task.
-
#initialize(database) ⇒ TaskMapper
constructor
initialization.
-
#persist_tasks(tasks) ⇒ Object
method to persist a list of Task::Tasks to the database.
-
#query_max_task_id ⇒ Integer
method to query the max id of the task table.
-
#query_task(id) ⇒ Task::Task | nil
method to search for a task by its id.
Methods inherited from Base
Constructor Details
#initialize(database) ⇒ TaskMapper
initialization
8 9 10 |
# File 'lib/data/sqlite/task_mapper.rb', line 8 def initialize(database) super(database) end |
Instance Method Details
#create_task_from_result(result) ⇒ Object (private)
method to create a Task::Task from a result entry
49 50 51 52 53 |
# File 'lib/data/sqlite/task_mapper.rb', line 49 def create_task_from_result(result) Task::Task.new(result["Id"], Time.parse(result["Start"]), Time.parse(result["End"]), result["Description"]) end |
#generate_tasks ⇒ Array
public method to transform database persons to entity Task::Task
14 15 16 17 18 19 20 21 |
# File 'lib/data/sqlite/task_mapper.rb', line 14 def generate_tasks results = @db_base.query_tasks tasks = Array.new() results.each { |result| tasks << create_task_from_result(result) } return tasks end |
#persist_tasks(tasks) ⇒ Object
method to persist a list of Task::Tasks to the database
25 26 27 28 29 30 31 |
# File 'lib/data/sqlite/task_mapper.rb', line 25 def persist_tasks(tasks) tasks.each { |task| @db_base.insert_task(task.id, task.start_time, task.end_time, task.description) } nil end |
#query_max_task_id ⇒ Integer
method to query the max id of the task table
41 42 43 |
# File 'lib/data/sqlite/task_mapper.rb', line 41 def query_max_task_id check_max_id(@db_base.query_max_task_id.next) end |
#query_task(id) ⇒ Task::Task | nil
method to search for a task by its id
35 36 37 |
# File 'lib/data/sqlite/task_mapper.rb', line 35 def query_task(id) create_task_from_result(@db_base.query_task(id).next) end |