Module: Attend

Defined in:
lib/attend.rb,
lib/attend/version.rb,
lib/attend/get_absent_days.rb,
lib/attend/register_attendances.rb

Defined Under Namespace

Classes: GetAbsentDays, RegisterAttendances

Constant Summary collapse

VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.register(email:, from:, to:, check_in:, check_out:, dry_run: true) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/attend.rb', line 14

def self.register(email:, from:, to:, check_in:, check_out:, dry_run: true)
  absent_days = GetAbsentDays.new(zoho: ZOHO_API).call(email: email, from: from, to: to)

  if absent_days.empty?
    puts "No absent days between #{from} and #{to}"
    return
  end

  attendances = absent_days.map do |day|
    day_beginning = day.to_datetime

    Zoho::People::Attendance.new(email: email,
                                 check_in: day_beginning.new_offset("+#{check_in}"),
                                 check_out: day_beginning.new_offset("+#{check_out}"))
  end

  RegisterAttendances.new(zoho: ZOHO_API, dry_run: dry_run).call(attendances)
end