Class: Worklog::Entities::Track
- Inherits:
-
Object
- Object
- Worklog::Entities::Track
- 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
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#reward ⇒ Object
readonly
Returns the value of attribute reward.
-
#spent ⇒ Object
readonly
Returns the value of attribute spent.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Instance Method Summary collapse
-
#initialize(date, spent:, rate: 0, task: "") ⇒ Track
constructor
A new instance of Track.
Constructor Details
#initialize(date, spent:, rate: 0, task: "") ⇒ Track
Returns a new instance of Track.
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
#date ⇒ Object (readonly)
Returns the value of attribute date.
11 12 13 |
# File 'lib/worklog/entities/track.rb', line 11 def date @date end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
12 13 14 |
# File 'lib/worklog/entities/track.rb', line 12 def rate @rate end |
#reward ⇒ Object (readonly)
Returns the value of attribute reward.
15 16 17 |
# File 'lib/worklog/entities/track.rb', line 15 def reward @reward end |
#spent ⇒ Object (readonly)
Returns the value of attribute spent.
14 15 16 |
# File 'lib/worklog/entities/track.rb', line 14 def spent @spent end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
13 14 15 |
# File 'lib/worklog/entities/track.rb', line 13 def task @task end |