Class: TimeCrunch::TimeEntry
- Inherits:
-
Object
- Object
- TimeCrunch::TimeEntry
- Includes:
- Enumerable
- Defined in:
- lib/time_crunch/time_entry.rb
Instance Attribute Summary collapse
-
#employee ⇒ Object
readonly
Returns the value of attribute employee.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #clock_in? ⇒ Boolean
- #clock_out? ⇒ Boolean
- #direction ⇒ Object
-
#initialize(csv_row, employee_map) ⇒ TimeEntry
constructor
A new instance of TimeEntry.
- #to_s ⇒ Object
- #value_by_index(ind) ⇒ Object
Constructor Details
#initialize(csv_row, employee_map) ⇒ TimeEntry
Returns a new instance of TimeEntry.
6 7 8 9 10 11 12 |
# File 'lib/time_crunch/time_entry.rb', line 6 def initialize(csv_row, employee_map) raise 'Row does not have four columns' unless csv_row.size == 4 @clock_in = csv_row[0] == '3' @employee = employee_map.key?(csv_row[1]) ? employee_map[csv_row[1]] : csv_row[1] @timestamp = Time.parse("#{csv_row[2]} #{csv_row[3]}") end |
Instance Attribute Details
#employee ⇒ Object (readonly)
Returns the value of attribute employee.
4 5 6 |
# File 'lib/time_crunch/time_entry.rb', line 4 def employee @employee end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
4 5 6 |
# File 'lib/time_crunch/time_entry.rb', line 4 def @timestamp end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 |
# File 'lib/time_crunch/time_entry.rb', line 38 def <=>(other) <=> other. end |
#clock_in? ⇒ Boolean
14 15 16 |
# File 'lib/time_crunch/time_entry.rb', line 14 def clock_in? @clock_in end |
#clock_out? ⇒ Boolean
18 19 20 |
# File 'lib/time_crunch/time_entry.rb', line 18 def clock_out? !clock_in? end |
#direction ⇒ Object
22 23 24 |
# File 'lib/time_crunch/time_entry.rb', line 22 def direction clock_in? ? 'IN' : 'OUT' end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/time_crunch/time_entry.rb', line 42 def to_s "<direction: #{direction}, employee: #{employee}, timestamp: #{.strftime('%Y-%m-%d %H:%M:%S')}>" end |
#value_by_index(ind) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/time_crunch/time_entry.rb', line 26 def value_by_index(ind) raise IndexError if ind > 2 || ind < 0 case ind when 0 direction when 1 employee when 2 .strftime('%Y-%m-%d %H:%M:%S') end end |