Class: TimeCrunch::TimeEntry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/time_crunch/time_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#employeeObject (readonly)

Returns the value of attribute employee.



4
5
6
# File 'lib/time_crunch/time_entry.rb', line 4

def employee
  @employee
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



4
5
6
# File 'lib/time_crunch/time_entry.rb', line 4

def timestamp
  @timestamp
end

Instance Method Details

#<=>(other) ⇒ Object



38
39
40
# File 'lib/time_crunch/time_entry.rb', line 38

def <=>(other)
  timestamp <=> other.timestamp
end

#clock_in?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/time_crunch/time_entry.rb', line 14

def clock_in?
  @clock_in
end

#clock_out?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/time_crunch/time_entry.rb', line 18

def clock_out?
  !clock_in?
end

#directionObject



22
23
24
# File 'lib/time_crunch/time_entry.rb', line 22

def direction
  clock_in? ? 'IN' : 'OUT'
end

#to_sObject



42
43
44
# File 'lib/time_crunch/time_entry.rb', line 42

def to_s
  "<direction: #{direction}, employee: #{employee}, timestamp: #{timestamp.strftime('%Y-%m-%d %H:%M:%S')}>"
end

#value_by_index(ind) ⇒ Object

Raises:

  • (IndexError)


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
    timestamp.strftime('%Y-%m-%d %H:%M:%S')
  end
end