Class: Cxeed::Attendance

Inherits:
Object
  • Object
show all
Defined in:
lib/cxeed/attendance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, arrive_at, leave_at) ⇒ Attendance

Returns a new instance of Attendance.



8
9
10
11
12
# File 'lib/cxeed/attendance.rb', line 8

def initialize(date, arrive_at, leave_at)
  @date = Time.parse(date, Time.now)
  @arrive_at = parse_time(arrive_at)
  @leave_at = parse_time(leave_at)
end

Instance Attribute Details

#arrive_atObject

Returns the value of attribute arrive_at.



6
7
8
# File 'lib/cxeed/attendance.rb', line 6

def arrive_at
  @arrive_at
end

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/cxeed/attendance.rb', line 6

def date
  @date
end

#leave_atObject

Returns the value of attribute leave_at.



6
7
8
# File 'lib/cxeed/attendance.rb', line 6

def leave_at
  @leave_at
end

Instance Method Details

#attendance_timeObject



32
33
34
# File 'lib/cxeed/attendance.rb', line 32

def attendance_time
  "#{ @arrive_at&.strftime('%H:%M') } - #{ @leave_at&.strftime('%H:%M') } (#{ '%.2f' % working_hour }) "
end

#parse_time(time) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cxeed/attendance.rb', line 14

def parse_time(time)
  if time.empty? || time == '  :  '
    nil
  else
    Time.parse(time, Time.now)
  end
end

#working_hourObject



23
24
25
26
27
28
29
30
# File 'lib/cxeed/attendance.rb', line 23

def working_hour
  if @leave_at.nil? || @arrive_at.nil?
    0
  else
    # TODO: 午前休とかに対応する
    (@leave_at - @arrive_at) / 3600 - 1
  end
end