Class: Cxeed::Attendance
- Inherits:
-
Object
- Object
- Cxeed::Attendance
- Defined in:
- lib/cxeed/attendance.rb
Instance Attribute Summary collapse
-
#arrive_at ⇒ Object
Returns the value of attribute arrive_at.
-
#date ⇒ Object
Returns the value of attribute date.
-
#leave_at ⇒ Object
Returns the value of attribute leave_at.
Instance Method Summary collapse
- #attendance_time ⇒ Object
-
#initialize(date, arrive_at, leave_at) ⇒ Attendance
constructor
A new instance of Attendance.
- #parse_time(time) ⇒ Object
- #working_hour ⇒ Object
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_at ⇒ Object
Returns the value of attribute arrive_at.
6 7 8 |
# File 'lib/cxeed/attendance.rb', line 6 def arrive_at @arrive_at end |
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/cxeed/attendance.rb', line 6 def date @date end |
#leave_at ⇒ Object
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_time ⇒ Object
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_hour ⇒ Object
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 |