class WorkingTimes::Record
Constants
- OPTIONS
Attributes
comment[R]
duration[R]
timestamp[R]
Public Class Methods
new(timestamp:, comment: nil, duration: nil)
click to toggle source
# File lib/working_times/record.rb, line 12 def initialize(timestamp:, comment: nil, duration: nil) @timestamp = timestamp @comment = comment @duration = duration end
Public Instance Methods
finish()
click to toggle source
# File lib/working_times/record.rb, line 24 def finish updated_csv = '' CSV.filter(File.open(path_current_term), updated_csv, OPTIONS) do |row| next if row.header_row? next unless row['finished_at'].empty? row['finished_at'] = timestamp.rfc3339 row['comment'] = comment end File.write(path_current_term, updated_csv) end
rest()
click to toggle source
# File lib/working_times/record.rb, line 36 def rest parse_rest_sec updated_csv = '' CSV.filter(File.open(path_current_term), updated_csv, OPTIONS) do |row| next if row.header_row? next unless row['finished_at'].empty? row['rest_sec'] = @rest_sec end File.write(path_current_term, updated_csv) end
start()
click to toggle source
# File lib/working_times/record.rb, line 18 def start CSV.open(path_current_term, 'a+', OPTIONS) do |csv| csv.puts([timestamp.rfc3339, '', 0, comment]) end end
Private Instance Methods
parse_rest_sec()
click to toggle source
# File lib/working_times/record.rb, line 51 def parse_rest_sec @rest_sec = 0 if /(?<hour>\d+)\s*h/ =~ duration @rest_sec += hour.to_i * 3600 end if /(?<minute>\d+)\s*m/ =~ duration @rest_sec += minute.to_i * 60 end end