Class: TimeDistribution::WorkDay
- Inherits:
-
Object
- Object
- TimeDistribution::WorkDay
- Defined in:
- lib/time_distribution/work_day.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_task!(task) ⇒ Object
-
#initialize(date, *tasks) ⇒ WorkDay
constructor
A new instance of WorkDay.
- #time_worked(*subjects) ⇒ Object
- #to_hours(*subjects) ⇒ Object
- #to_md ⇒ Object
- #to_ssv ⇒ Object
Constructor Details
#initialize(date, *tasks) ⇒ WorkDay
Returns a new instance of WorkDay.
20 21 22 23 24 25 26 27 |
# File 'lib/time_distribution/work_day.rb', line 20 def initialize(date, *tasks) @date = Chronic.parse(date) @tasks = if tasks.length == 1 && !tasks.first.is_a?(Task) TaskList.new(*tasks) else TaskList.new(tasks) end end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
9 10 11 |
# File 'lib/time_distribution/work_day.rb', line 9 def date @date end |
#tasks ⇒ Object (readonly)
Returns the value of attribute tasks.
9 10 11 |
# File 'lib/time_distribution/work_day.rb', line 9 def tasks @tasks end |
Class Method Details
.from_map(map_data) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/time_distribution/work_day.rb', line 11 def self.from_map(map_data) self.new( map_data['date'], *(map_data['tasks'].map { |t| Task.from_map t }) ) end |
Instance Method Details
#==(other) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/time_distribution/work_day.rb', line 29 def ==(other) ( @date == other.date && @tasks == other.tasks ) end |
#add_task!(task) ⇒ Object
37 38 39 40 |
# File 'lib/time_distribution/work_day.rb', line 37 def add_task!(task) @tasks << task self end |
#time_worked(*subjects) ⇒ Object
42 |
# File 'lib/time_distribution/work_day.rb', line 42 def time_worked(*subjects) @tasks.time_worked *subjects end |
#to_hours(*subjects) ⇒ Object
44 |
# File 'lib/time_distribution/work_day.rb', line 44 def to_hours(*subjects) @tasks.to_hours *subjects end |
#to_md ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/time_distribution/work_day.rb', line 46 def to_md ( @date.strftime('%b %-d, %Y') + "\n============================\n" + @tasks.to_md ) end |
#to_ssv ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/time_distribution/work_day.rb', line 54 def to_ssv ( "# #{@date.strftime('%b %-d, %Y')}\n" + ( if block_given? @tasks.to_ssv { |key| yield(key) } else @tasks.to_ssv end ) ) end |