Class: TimeTally::TimeEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/time_tally/time_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task:, duration:) ⇒ TimeEntry

Returns a new instance of TimeEntry.



5
6
7
8
# File 'lib/time_tally/time_entry.rb', line 5

def initialize(task:, duration:)
  @task = task
  @duration = duration
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



3
4
5
# File 'lib/time_tally/time_entry.rb', line 3

def duration
  @duration
end

#taskObject (readonly)

Returns the value of attribute task.



3
4
5
# File 'lib/time_tally/time_entry.rb', line 3

def task
  @task
end

Class Method Details

.from_lines(lines) ⇒ Object



10
11
12
13
14
# File 'lib/time_tally/time_entry.rb', line 10

def self.from_lines(lines)
  task = lines[0]
  duration = lines[1..-1].select { |s| s =~ /^\d+:\d{2}:\d{2}$/ }.first
  TimeEntry.new(task: task, duration: Duration.new(duration))
end

Instance Method Details

#to_sObject



16
17
18
# File 'lib/time_tally/time_entry.rb', line 16

def to_s
  "%-40s %s" % [task, duration]
end