Class: WorkingTimes::Record
- Inherits:
-
Object
- Object
- WorkingTimes::Record
- Includes:
- State
- Defined in:
- lib/working_times/record.rb
Constant Summary collapse
- OPTIONS =
{ headers: true, return_headers: true, write_headers: true }.freeze
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(timestamp:, comment: nil, duration: nil) ⇒ Record
constructor
A new instance of Record.
- #rest ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(timestamp:, comment: nil, duration: nil) ⇒ Record
Returns a new instance of Record.
12 13 14 15 16 |
# File 'lib/working_times/record.rb', line 12 def initialize(timestamp:, comment: nil, duration: nil) @timestamp = @comment = comment @duration = duration end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
10 11 12 |
# File 'lib/working_times/record.rb', line 10 def comment @comment end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
10 11 12 |
# File 'lib/working_times/record.rb', line 10 def duration @duration end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
10 11 12 |
# File 'lib/working_times/record.rb', line 10 def @timestamp end |
Instance Method Details
#finish ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# 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'] = .rfc3339 row['comment'] = comment end File.write(path_current_term, updated_csv) end |
#rest ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
18 19 20 21 22 |
# File 'lib/working_times/record.rb', line 18 def start CSV.open(path_current_term, 'a+', OPTIONS) do |csv| csv.puts([.rfc3339, '', 0, comment]) end end |