class TimeCrunch::TimeEntry

Attributes

employee[R]
timestamp[R]

Public Class Methods

new(csv_row, employee_map) click to toggle source
# 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

Public Instance Methods

<=>(other) click to toggle source
# File lib/time_crunch/time_entry.rb, line 38
def <=>(other)
  timestamp <=> other.timestamp
end
clock_in?() click to toggle source
# File lib/time_crunch/time_entry.rb, line 14
def clock_in?
  @clock_in
end
clock_out?() click to toggle source
# File lib/time_crunch/time_entry.rb, line 18
def clock_out?
  !clock_in?
end
direction() click to toggle source
# File lib/time_crunch/time_entry.rb, line 22
def direction
  clock_in? ? 'IN' : 'OUT'
end
to_s() click to toggle source
# 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) click to toggle source
# 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