Class: Worklog::Entities::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/worklog/entities/track.rb

Overview

This class represent the abstraction of a timelog item

Constant Summary collapse

MAX_MINUTES =
1440

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date, spent:, rate: 0, task: "") ⇒ Track

Returns a new instance of Track.

Parameters:

  • date (Time)

    the date of the track

  • rate (Float) (defaults to: 0)

    the rate of the track

  • spent (Integer)

    minutes spent of the track

  • task (String) (defaults to: "")

    the task descritpion of the track

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/worklog/entities/track.rb', line 21

def initialize(date, spent:,  rate: 0, task: "")
  # the spent cannot be more than a day of 24 hours
  raise ArgumentError, ":spent exceeds 24 hours" if spent > MAX_MINUTES
  # the date cannot be in the future
  date = date.to_date unless date.is_a? Date
  raise ArgumentError, ":date in the future" if date > Date.today
  @date = date
  @rate = rate
  @task = task
  @spent = spent
  reward = BigDecimal(spent.to_s) / BigDecimal(60) * BigDecimal(rate.to_s)
  @reward = reward.round(2, :half_down)
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



11
12
13
# File 'lib/worklog/entities/track.rb', line 11

def date
  @date
end

#rateObject (readonly)

Returns the value of attribute rate.



12
13
14
# File 'lib/worklog/entities/track.rb', line 12

def rate
  @rate
end

#rewardObject (readonly)

Returns the value of attribute reward.



15
16
17
# File 'lib/worklog/entities/track.rb', line 15

def reward
  @reward
end

#spentObject (readonly)

Returns the value of attribute spent.



14
15
16
# File 'lib/worklog/entities/track.rb', line 14

def spent
  @spent
end

#taskObject (readonly)

Returns the value of attribute task.



13
14
15
# File 'lib/worklog/entities/track.rb', line 13

def task
  @task
end