Class: Menu::TimeMenu::MonthtimeMenu

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

Overview

menu class to present the available query options for a given month 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

#initializeMonthtimeMenu

initialization



12
13
14
# File 'lib/menu/worktime/monthtime_menu.rb', line 12

def initialize
  super("month")
end

Instance Method Details

#calculate_month_and_next_month(year, month) ⇒ Hash (private)

method to calculate the time boundaries for the given month

Parameters:

  • year (Integer)

    the requested year

  • month (Integer)

    the requested month

Returns:

  • (Hash)

    a hash containing the two time boundaries



47
48
49
50
# File 'lib/menu/worktime/monthtime_menu.rb', line 47

def calculate_month_and_next_month(year, month)
  check_date = Time.new(year, month)
  {:actual => check_date, :next => check_date.next_month}
end

#retrieve_tasksHash (private)

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

Returns:

  • (Hash)

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



22
23
24
# File 'lib/menu/worktime/monthtime_menu.rb', line 22

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 month

Returns:

  • (Hash)

    a hash with the hours for each type of task



29
30
31
32
# File 'lib/menu/worktime/monthtime_menu.rb', line 29

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

#set_boundariesObject (private)

method to calculate the date boundaries of the provided user input



35
36
37
38
39
40
41
# File 'lib/menu/worktime/monthtime_menu.rb', line 35

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