Class: Menu::TimeMenu::WeektimeMenu

Inherits:
IntervaltimeMenu show all
Defined in:
lib/menu/worktime/weektime_menu.rb

Overview

menu class to present the available query options for a given week and for a given entity, identified by its id

Instance Attribute Summary

Attributes inherited from TimeMenu

#additions, #time_string, #values

Attributes inherited from Base

#menu_description, #menu_items

Instance Method Summary collapse

Methods inherited from IntervaltimeMenu

#get_input_values, #set_values

Methods inherited from TimeMenu

#calculate_worktime, #check_attributes, #check_time_string, #define_menu_items, #determine_action, #get_input_values, #output_to_csv, #print_all_tasks, #print_tasks_in_interval, #print_tasks_to_key, #retrieve_and_print_worktime

Methods inherited from Base

#add_menu_item, #define_menu_items, #determine_action, #get_entry, #handle_wrong_option, #print_menu

Constructor Details

#initializeWeektimeMenu

initialization



10
11
12
# File 'lib/menu/worktime/weektime_menu.rb', line 10

def initialize
  super("week")
end

Instance Method Details

#calculate_start_and_end_day(year, calendar_week) ⇒ Hash (private)

method to calculate the time boundaries for the given week

Parameters:

  • year (Integer)

    the requested year

  • calendar_week (Integer)

    the requested week

Returns:

  • (Hash)

    a hash containing the two time boundaries



44
45
46
47
48
49
# File 'lib/menu/worktime/weektime_menu.rb', line 44

def calculate_start_and_end_day(year, calendar_week)
  start_time = get_monday_of_calendar_week(year, calendar_week)
  end_time = get_next_monday(start_time)
  {:actual => Time.new(start_time.year, start_time.month, start_time.day),
   :next => Time.new(end_time.year, end_time.month, end_time.day)}
end

#get_monday_of_calendar_week(year, calendar_week) ⇒ Time (private)

method to calculate the lower time boundary for the given week (the start of the week)

Parameters:

  • year (Integer)

    the requested year

  • calendar_week (Integer)

    the requested week of the year

Returns:

  • (Time)

    the start of the monday in the requested week



56
57
58
59
60
61
62
# File 'lib/menu/worktime/weektime_menu.rb', line 56

def get_monday_of_calendar_week(year, calendar_week)
  start = Time.new(year)

  # Monday of calendar week 1
  start = get_next_monday(start)
  start + (calendar_week - 2) * 7 * 60 * 60 * 24
end

#get_next_monday(time) ⇒ Time (private)

method to calculate the upper time boundary for the given week (the end of the week)

Parameters:

  • time (Time)

    the start time of the requested week

Returns:

  • (Time)

    the time of the monday of the follwing week



68
69
70
# File 'lib/menu/worktime/weektime_menu.rb', line 68

def get_next_monday(time)
  time + (7 - time.get_int_wday) * 60 * 60 * 24
end

#retrieve_tasksHash (private)

method to retrieve all task that started, ended or took place within the given week for the provided id

Returns:

  • (Hash)

    a hash mapping (task_type => Array) holding the queried tasks



20
21
22
# File 'lib/menu/worktime/weektime_menu.rb', line 20

def retrieve_tasks
  Query.get_data(@values[:id], @values[:start_time], @values[:end_time])
end

#retrieve_worktimeHash (private)

method to retrieve the overall worktime for an entity with the given id for the given week

Returns:

  • (Hash)

    a hash with the hours for each type of task



27
28
29
30
# File 'lib/menu/worktime/weektime_menu.rb', line 27

def retrieve_worktime
  Query.get_weekly_worktime(@values[:id], @values[:start_time],
                                       @values[:end_time])
end

#set_boundariesObject (private)

method to calculate the date boundaries of the provided user input



33
34
35
36
37
38
# File 'lib/menu/worktime/weektime_menu.rb', line 33

def set_boundaries
  days = calculate_start_and_end_day(@values[:year], @values[:time_frame])
  set_values(days)
  return "Calculated interval for week from input:" \
         " #{days[:actual]} - #{days[:next]}"
end