Class: DailyLog

Inherits:
Object
  • Object
show all
Includes:
Hashify
Defined in:
worklog/daily_log.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hashify

#to_hash

Constructor Details

#initialize(params = {}) ⇒ DailyLog

Returns a new instance of DailyLog.



12
13
14
15
# File 'worklog/daily_log.rb', line 12

def initialize(params = {})
  @date = params[:date]
  @entries = params[:entries]
end

Instance Attribute Details

#dateObject

Represents a single day’s work log.



10
11
12
# File 'worklog/daily_log.rb', line 10

def date
  @date
end

#entriesObject

Represents a single day’s work log.



10
11
12
# File 'worklog/daily_log.rb', line 10

def entries
  @entries
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'worklog/daily_log.rb', line 31

def ==(other)
  date == other.date && entries == other.entries
end

#peopleObject



22
23
24
25
26
27
28
29
# File 'worklog/daily_log.rb', line 22

def people
  # 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 ~.
  #
  # @return [Hash<String, Integer>]
  entries.map(&:people).flatten.tally
end

#people?Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'worklog/daily_log.rb', line 17

def people?
  # Returns true if there are people mentioned in any entry of the current day.
  people.size.positive?
end