class Ruboty::Handlers::Timecard

Constants

DATETIME_FORMAT
DATE_FORMAT
SEPARATOR

Public Instance Methods

punch(message) click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 12
def punch(message)
  @member = message.from_name || "Anonymous"
  storage[member_row, member_column] = @member
  storage[date_row, date_column] = today_timestamp
  storage[date_row, member_column] = timestamp
end

Private Instance Methods

date_column() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 38
def date_column
  1
end
date_row() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 42
def date_row
  begin
    latest_date = Date.parse(storage[storage.num_rows, 1])
    latest_date == Date.today ? storage.num_rows : storage.num_rows + 1
  rescue
    2
  end
end
end_time() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 68
def end_time
  Time.now.strftime(DATETIME_FORMAT)
end
member_column() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 29
def member_column
  if storage.num_rows > 0
    member_index = storage.rows[0].find_index(@member)
    member_index.nil? ? storage.num_cols + 1 : member_index + 1
  else
    2
  end
end
member_row() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 25
def member_row
  1
end
start_time() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 59
def start_time
  value = storage[date_row, member_column]
  if value.empty?
    Time.now.strftime(DATETIME_FORMAT)
  else
    value.split(SEPARATOR).first
  end
end
storage() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 21
def storage
  robot.brain.data[0]
end
timestamp() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 55
def timestamp
  [start_time, end_time].join(SEPARATOR)
end
today_timestamp() click to toggle source
# File lib/ruboty/handlers/timecard.rb, line 51
def today_timestamp
  Time.now.strftime(DATE_FORMAT)
end