Class: Kobot::Engine
- Inherits:
-
Object
- Object
- Kobot::Engine
- Defined in:
- lib/kobot/engine.rb
Overview
The core class that launches browser, logins to KOT, reads today record, and conducts clock in or clock out action based on config.
Instance Method Summary collapse
-
#initialize ⇒ Engine
constructor
A new instance of Engine.
-
#start ⇒ Object
The entrance where the whole flow starts.
Constructor Details
#initialize ⇒ Engine
Returns a new instance of Engine.
9 10 11 12 13 |
# File 'lib/kobot/engine.rb', line 9 def initialize @now = Time.now.getlocal(Config.kot_timezone_offset) @today = @now.strftime(Config.kot_date_format) @top_url = Config.kot_url end |
Instance Method Details
#start ⇒ Object
The entrance where the whole flow starts.
It exits early if today is weekend or marked as to skip by the #Config.skip specified from command line option --skip.
Unexpected behavior such as record appearing as holiday on the web or failure of clock in/out action is handled within the method by logging and/or email notifications if enabled.
System errors or any unknown exceptions occurred if any are to be popped up and should be handled by the outside caller.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kobot/engine.rb', line 26 def start return unless should_run_today? launch_browser login read_today_record validate_today_record! if Config.clock == :in clock_in! else clock_out! end logout rescue KotRecordError => e Kobot.logger.warn(e.) Mailer.send((status: e.)) logout rescue KotClockInError => e Kobot.logger.warn e. Mailer.send((clock: :in, status: e.)) logout rescue KotClockOutError => e Kobot.logger.warn e. Mailer.send((clock: :out, status: e.)) logout rescue StandardError => e Kobot.logger.error(e.) Kobot.logger.error(e.backtrace) Mailer.send((status: e.)) logout ensure close_browser end |