Class: Worklog::DailyLog
Overview
DailyLog is a container for a day’s work log.
Instance Attribute Summary collapse
-
#date ⇒ Object
Represents a single day’s work log.
-
#entries ⇒ Object
Represents a single day’s work log.
Class Method Summary collapse
-
.from_hash(hash) ⇒ DailyLog
Create a DailyLog from a hash with symbolized keys.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Equals method to compare two DailyLog objects.
-
#initialize(params = {}) ⇒ DailyLog
constructor
A new instance of DailyLog.
-
#people ⇒ Hash<String, Integer>
Returns a hash of people mentioned in the log for the current day with the number of times they are mentioned.
-
#people? ⇒ Boolean
Returns true if there are people mentioned in any entry of the current day.
-
#tags ⇒ Array<String>
Returns a sorted list of tags used in the entries for the current day.
Methods included from Hashify
Constructor Details
#initialize(params = {}) ⇒ DailyLog
Returns a new instance of DailyLog.
14 15 16 17 |
# File 'lib/daily_log.rb', line 14 def initialize(params = {}) @date = params[:date] @entries = params[:entries] end |
Instance Attribute Details
#date ⇒ Object
Represents a single day’s work log.
12 13 14 |
# File 'lib/daily_log.rb', line 12 def date @date end |
#entries ⇒ Object
Represents a single day’s work log.
12 13 14 |
# File 'lib/daily_log.rb', line 12 def entries @entries end |
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean
Equals method to compare two DailyLog objects.
62 63 64 |
# File 'lib/daily_log.rb', line 62 def ==(other) date == other.date && entries == other.entries end |
#people ⇒ Hash<String, Integer>
Returns a hash of people mentioned in the log for the current day with the number of times they are mentioned. People are defined as words starting with @ or ~.
31 32 33 |
# File 'lib/daily_log.rb', line 31 def people entries.map { |entry| entry.people.to_a }.flatten.tally end |
#people? ⇒ Boolean
Returns true if there are people mentioned in any entry of the current day.
22 23 24 |
# File 'lib/daily_log.rb', line 22 def people? people.size.positive? end |
#tags ⇒ Array<String>
Returns a sorted list of tags used in the entries for the current day.
43 44 45 |
# File 'lib/daily_log.rb', line 43 def entries.flat_map(&:tags).uniq.sort end |