Class: Worklog::Entities::Sheet
- Inherits:
-
Object
- Object
- Worklog::Entities::Sheet
- Defined in:
- lib/worklog/entities/sheet.rb
Overview
This class represent sheet of tracks collection
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#date_format ⇒ Object
Returns the value of attribute date_format.
-
#hourly_rate ⇒ Object
Returns the value of attribute hourly_rate.
-
#source ⇒ Object
Returns the value of attribute source.
-
#title ⇒ Object
Returns the value of attribute title.
-
#tracks ⇒ Object
readonly
Returns the value of attribute tracks.
Instance Method Summary collapse
-
#initialize ⇒ Sheet
constructor
A new instance of Sheet.
-
#merge!(sheet) ⇒ Object
The method merges tracks from sheet passed as param.
- #reward ⇒ Object
- #spent ⇒ Object
-
#spent_for(date) ⇒ Object
The method calculates sum(spent) for provided date.
-
#track(date, spent:, task:, rate: nil) ⇒ Track
This method adds new track to the sheet It will pring warning, when total spent for one date exceeds 24h.
Constructor Details
#initialize ⇒ Sheet
Returns a new instance of Sheet.
20 21 22 23 24 25 26 |
# File 'lib/worklog/entities/sheet.rb', line 20 def initialize @tracks = {} @date_format = "%Y-%m-%d" @hourly_rate = 0 @title = "Unspecified" @author = "Unspecified" end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
14 15 16 |
# File 'lib/worklog/entities/sheet.rb', line 14 def @author end |
#date_format ⇒ Object
Returns the value of attribute date_format.
16 17 18 |
# File 'lib/worklog/entities/sheet.rb', line 16 def date_format @date_format end |
#hourly_rate ⇒ Object
Returns the value of attribute hourly_rate.
17 18 19 |
# File 'lib/worklog/entities/sheet.rb', line 17 def hourly_rate @hourly_rate end |
#source ⇒ Object
Returns the value of attribute source.
15 16 17 |
# File 'lib/worklog/entities/sheet.rb', line 15 def source @source end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/worklog/entities/sheet.rb', line 13 def title @title end |
#tracks ⇒ Object (readonly)
Returns the value of attribute tracks.
12 13 14 |
# File 'lib/worklog/entities/sheet.rb', line 12 def tracks @tracks end |
Instance Method Details
#merge!(sheet) ⇒ Object
The method merges tracks from sheet passed as param
57 58 59 60 61 62 63 |
# File 'lib/worklog/entities/sheet.rb', line 57 def merge!(sheet) @tracks.merge!(sheet.tracks) do |date, these_tracks, merge_tracks| puts "Warning! Date duplication detected in '#{@source}' and '#{sheet.source}'" puts "Please, check these files manually for '#{date.to_s}'" these_tracks + merge_tracks end end |
#reward ⇒ Object
71 72 73 74 75 |
# File 'lib/worklog/entities/sheet.rb', line 71 def reward @tracks.inject(0) {|sum, (d, t)| sum + t.map(&:reward).inject(:+) } end |
#spent ⇒ Object
65 66 67 68 69 |
# File 'lib/worklog/entities/sheet.rb', line 65 def spent @tracks.inject(0) {|sum, (d, t)| sum + t.map(&:spent).inject(:+) } end |
#spent_for(date) ⇒ Object
The method calculates sum(spent) for provided date
52 53 54 |
# File 'lib/worklog/entities/sheet.rb', line 52 def spent_for(date) @tracks[date].map(&:spent).inject(:+) end |
#track(date, spent:, task:, rate: nil) ⇒ Track
This method adds new track to the sheet It will pring warning, when total spent for one date exceeds 24h
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/worklog/entities/sheet.rb', line 35 def track(date, spent:, task:, rate: nil) @tracks[date] ||= [] @tracks[date] << Track.new( date, spent: spent, task: task, rate: rate || @hourly_rate ) if @tracks[date].size > 1 && spent_for(date) > Track::MAX_MINUTES puts "Warning! Total spent for #{date} greater than 24 hours" end @tracks[date].last end |