class Dovico::App
Constants
- DESCRIPTION
- NAME
Public Class Methods
new()
click to toggle source
# File lib/dovico/app.rb, line 17 def initialize config.config_file_base_name = 'dovico' config.describes_application app_name: NAME, app_version: Dovico::VERSION, app_description: DESCRIPTION add_script_options ApiClient.initialize!(config["client_token"], config["user_token"]) end
Public Instance Methods
add_script_options()
click to toggle source
# File lib/dovico/app.rb, line 27 def add_script_options config.add_command_line_section('Display informations') do |slop| slop.on :myself, 'Display info on yourself', argument: false slop.on :tasks, 'Display info on tasks', argument: false end config.add_command_line_section('Fill the timesheets') do |slop| slop.on :fill, 'Fill the timesheet', argument: false end config.add_command_line_section('Show the timesheets') do |slop| slop.on :show, 'Show the filled timesheets', argument: false end config.add_command_line_section('Submit the timesheets') do |slop| slop.on :submit, 'Submit timesheets', argument: false end config.add_command_line_section('Clear the timesheets') do |slop| slop.on :clear, 'Clear the timesheets', argument: false end config.add_command_line_section('Date options (required for --show, --fill, --submit and --clear)') do |slop| slop.on :current_week, 'Current week', argument: false slop.on :today, 'Current day', argument: false slop.on :day, 'Specific day', argument: true slop.on :start, 'Specific start day', argument: true slop.on :end, 'Specific end day', argument: true slop.on :week, 'Specific "commercial" week. See https://www.epochconverter.com/weeks/', argument: true, as: Integer slop.on :year, '[optional] Specifiy year (for --week option), default current year', argument: true, as: Integer end end
run()
click to toggle source
# File lib/dovico/app.rb, line 55 def run settings = ConfigParser.new(config) start_date, end_date = settings.date_options if settings.needs_help? display_help exit 0 end if config[:myself] display_myself end if config[:tasks] display_tasks end if config[:clear] clear_time_entries(start_date, end_date) end if config[:show] display_time_entries(start_date, end_date) end if config[:fill] time_entry_generator = TimeEntryGenerator.new( assignments: config["assignments"], employee_id: myself.id, ) time_entries = time_entry_generator.generate(start_date, end_date) if time_entries.count > 0 saved_time_entries = TimeEntry.batch_create!(time_entries) puts "#{saved_time_entries["TimeEntries"].count} Entries created between #{start_date} and #{end_date}" else puts "No entries to be created between #{start_date} and #{end_date}" end end if config[:submit] submitted_time_entries = TimeEntry.submit!(myself.id, start_date, end_date) puts "#{submitted_time_entries["TimeEntries"].count} Entries submitted between #{start_date} and #{end_date}" end end
Private Instance Methods
clear_time_entries(start_date, end_date)
click to toggle source
# File lib/dovico/app.rb, line 127 def clear_time_entries(start_date, end_date) time_entries = TimeEntry.search(start_date, end_date) if highline.agree("• #{time_entries.count} Time Entries to be deleted. Are you sure? (yes/no)") time_entries.each do |time_entry| time_entry.delete! end puts "✓ #{time_entries.count} Time Entries deleted" end end
display_help()
click to toggle source
# File lib/dovico/app.rb, line 137 def display_help puts config.command_line_help end
display_myself()
click to toggle source
# File lib/dovico/app.rb, line 107 def display_myself puts "Informations about yourself" puts myself puts "" end
display_tasks()
click to toggle source
# File lib/dovico/app.rb, line 113 def display_tasks puts "== List of available projects ==" puts Project.format_all puts "" end
display_time_entries(start_date, end_date)
click to toggle source
# File lib/dovico/app.rb, line 119 def display_time_entries(start_date, end_date) puts "== List of Time Entries between #{start_date} and #{end_date} ==" formatter = TimeEntryFormatter.new(Project.all) time_entries = TimeEntry.search(start_date, end_date) puts formatter.format_entries(time_entries) puts "" end
highline()
click to toggle source
# File lib/dovico/app.rb, line 141 def highline @highline ||= HighLine.new end
myself()
click to toggle source
# File lib/dovico/app.rb, line 103 def myself @myself ||= Employee.myself end