Class: Menu::TimeMenu::TimeMenu
- Defined in:
- lib/menu/worktime/time_menu.rb
Overview
menu class that serves as a base class for menus used to query information for a given time interval
Direct Known Subclasses
Instance Attribute Summary collapse
-
#additions ⇒ Array
readonly
private
An array with specific additions for the output.
-
#time_string ⇒ String
readonly
private
The string describing the given time interval.
-
#values ⇒ Hash
readonly
private
them as long as this menu is active.
Attributes inherited from Base
#menu_description, #menu_items
Instance Method Summary collapse
-
#calculate_worktime ⇒ String
private
method to calculate the overall worktime an return it.
-
#check_attributes ⇒ Object
private
method to check if the necessary input was already collected.
-
#check_time_string ⇒ Object
private
method check, if the subclass has set a value for the class attribute.
-
#define_menu_items ⇒ Object
private
method to define all printable menu items.
-
#determine_action(input) ⇒ Boolean
private
method to process the provided input.
-
#get_input_values(time_string) ⇒ Object
private
abstract
abstract method to retrieve the required input values.
-
#initialize(time_string) ⇒ TimeMenu
constructor
initialization.
-
#output_to_csv ⇒ Object
private
method to write the results into a csv formatted file.
-
#print_all_tasks ⇒ Object
private
method to print all the collected tasks.
-
#print_tasks_in_interval ⇒ Object
private
method to print all tasks in the given time interval.
-
#print_tasks_to_key(tasks) ⇒ Object
private
method to print all tasks collected to a specific key.
-
#retrieve_and_print_worktime ⇒ Object
private
method to print the worktime hours of the retrieved tasks.
-
#retrieve_tasks ⇒ Object
private
abstract
abstract method to retrieve the tasks for the given interval.
-
#retrieve_worktime ⇒ Object
private
abstract
abstract method to retrieve the worktime for the given interval.
-
#set_boundaries ⇒ Object
private
abstract
abstract method to calculate the date boundaries of the provided user input.
Methods inherited from Base
#add_menu_item, #get_entry, #handle_wrong_option, #print_menu
Constructor Details
#initialize(time_string) ⇒ TimeMenu
initialization
12 13 14 15 16 17 |
# File 'lib/menu/worktime/time_menu.rb', line 12 def initialize(time_string) @time_string = time_string @menu_description = "Queries for tasks done in the given " \ "#{@time_string}." super end |
Instance Attribute Details
#additions ⇒ Array (readonly, private)
Returns an array with specific additions for the output.
26 27 28 |
# File 'lib/menu/worktime/time_menu.rb', line 26 def additions @additions end |
#time_string ⇒ String (readonly, private)
Returns the string describing the given time interval.
21 22 23 |
# File 'lib/menu/worktime/time_menu.rb', line 21 def time_string @time_string end |
#values ⇒ Hash (readonly, private)
them as long as this menu is active
24 25 26 |
# File 'lib/menu/worktime/time_menu.rb', line 24 def values @values end |
Instance Method Details
#calculate_worktime ⇒ String (private)
method to calculate the overall worktime an return it
170 171 172 173 174 175 176 177 178 |
# File 'lib/menu/worktime/time_menu.rb', line 170 def calculate_worktime times = retrieve_worktime if (times[:over] > 0) time = times[:over] else time = times[:during] + times[:into] + times[:beyond] end "Worktime:; #{time} h" end |
#check_attributes ⇒ Object (private)
method to check if the necessary input was already collected
112 113 114 115 116 117 118 119 |
# File 'lib/menu/worktime/time_menu.rb', line 112 def check_attributes if (@values == nil) puts "Specify necessary informations: " get_input_values @additions = Array.new() end #check_time_string end |
#check_time_string ⇒ Object (private)
method check, if the subclass has set a value for the class attribute
123 124 125 126 127 128 129 |
# File 'lib/menu/worktime/time_menu.rb', line 123 def check_time_string if @time_string.eql?(nil) fail NotImplementedError, " Error: the subclass " \ "#{self.name.split("::").last} does not present a string for " \ "its attribute time_string".red end end |
#define_menu_items ⇒ Object (private)
method to define all printable menu items
39 40 41 42 43 44 45 46 47 |
# File 'lib/menu/worktime/time_menu.rb', line 39 def check_attributes @menu_description.concat("\n #{set_boundaries}") ("All tasks to a person in the given #{time_string}.", 1) ("Worktime of a person in that #{time_string}.", 2) ("All tasks running during the interval.", 3) ("Write Query result to csv-file.", 4) ("Cancel and return to previous menu.", 5) end |
#determine_action(input) ⇒ Boolean (private)
method to process the provided input
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/menu/worktime/time_menu.rb', line 53 def determine_action(input) case (input.to_i) when 1 then print_all_tasks when 2 then retrieve_and_print_worktime when 3 then print_tasks_in_interval when 4 then output_to_csv when 5 @values = nil return false else handle_wrong_option end return true end |
#get_input_values(time_string) ⇒ Object (private)
subclasses need to implement this method
abstract method to retrieve the required input values
32 33 34 35 36 |
# File 'lib/menu/worktime/time_menu.rb', line 32 def get_input_values(time_string) fail NotImplementedError, " Error: the subclass " \ "#{self.name.split("::").last} needs to implement the method: " \ "get_input_values from its parent class".red end |
#output_to_csv ⇒ Object (private)
method to write the results into a csv formatted file
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/menu/worktime/time_menu.rb', line 157 def output_to_csv if (@values[:result] != nil) @additions << calculate_worktime filename = get_entry("Specify output file: ") p = Menu.data_handler.find_person_by_id(@values[:id]) CSVWriter.output(filename, p, @values[:result], @additions) else puts "Nothing to write right now." end end |
#print_all_tasks ⇒ Object (private)
method to print all the collected tasks
132 133 134 135 136 137 138 |
# File 'lib/menu/worktime/time_menu.rb', line 132 def print_all_tasks tasks = retrieve_tasks @values[:result] = Array.new() tasks.each_key { |key| print_tasks_to_key(tasks[key]) if (tasks[key].size > 0) } end |
#print_tasks_in_interval ⇒ Object (private)
method to print all tasks in the given time interval
150 151 152 153 154 |
# File 'lib/menu/worktime/time_menu.rb', line 150 def print_tasks_in_interval tasks = retrieve_tasks @values[:result] = Array.new() print_tasks_to_key(tasks[:during]) end |
#print_tasks_to_key(tasks) ⇒ Object (private)
method to print all tasks collected to a specific key
142 143 144 145 146 147 |
# File 'lib/menu/worktime/time_menu.rb', line 142 def print_tasks_to_key(tasks) tasks.each { |task| puts task.to_string @values[:result] << task } end |
#retrieve_and_print_worktime ⇒ Object (private)
method to print the worktime hours of the retrieved tasks
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/menu/worktime/time_menu.rb', line 69 def retrieve_and_print_worktime times = retrieve_worktime puts "printing new worktime" if (times[:over] > 0) puts "Worktime: #{times[:over]} h" else puts "tasks.over: 0.0 h" puts "tasks.during: #{times[:during]} h" puts "tasks.into: #{times[:into]} h" puts "tasks.beyond: #{times[:beyond]} h" end end |
#retrieve_tasks ⇒ Object (private)
subclasses need to implement this method
abstract method to retrieve the tasks for the given interval
86 87 88 89 90 |
# File 'lib/menu/worktime/time_menu.rb', line 86 def retrieve_tasks fail NotImplementedError, " Error: the subclass " \ "#{self.name.split("::").last} needs to implement the method: " \ "retrieve_tasks from its parent class".red end |
#retrieve_worktime ⇒ Object (private)
subclasses need to implement this method
abstract method to retrieve the worktime for the given interval
95 96 97 98 99 |
# File 'lib/menu/worktime/time_menu.rb', line 95 def retrieve_worktime fail NotImplementedError, " Error: the subclass " \ "#{self.name.split("::").last} needs to implement the method: " \ "retrieve_worktime from its parent class".red end |
#set_boundaries ⇒ Object (private)
subclasses need to implement this method
abstract method to calculate the date boundaries of the provided user input
105 106 107 108 109 |
# File 'lib/menu/worktime/time_menu.rb', line 105 def set_boundaries fail NotImplementedError, " Error: the subclass " \ "#{Class.name.split("::").last} needs to implement the method: " \ "set_boundaries from its base class".red end |