Class: DailyLog

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

Overview

DailyLog is a container for a day’s work log.

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.



13
14
15
16
# File 'lib/daily_log.rb', line 13

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

Instance Attribute Details

#dateObject

Represents a single day’s work log.



11
12
13
# File 'lib/daily_log.rb', line 11

def date
  @date
end

#entriesObject

Represents a single day’s work log.



11
12
13
# File 'lib/daily_log.rb', line 11

def entries
  @entries
end

Instance Method Details

#==(other) ⇒ Boolean

Equals method to compare two DailyLog objects.

Parameters:

  • other (DailyLog)

    the other DailyLog object to compare with

Returns:

  • (Boolean)

    true if both DailyLog objects have the same date and entries, false otherwise



50
51
52
# File 'lib/daily_log.rb', line 50

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

#peopleHash<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 ~.

Returns:

  • (Hash<String, Integer>)


30
31
32
# File 'lib/daily_log.rb', line 30

def people
  entries.map(&:people).flatten.tally
end

#people?Boolean

Returns true if there are people mentioned in any entry of the current day.

Returns:

  • (Boolean)

    true if there are people mentioned, false otherwise.



21
22
23
# File 'lib/daily_log.rb', line 21

def people?
  people.size.positive?
end

#tagsArray<String>

Returns a sorted list of tags used in the entries for the current day.

Examples:

log = DailyLog.new(date: Date.today,
                   entries: [LogEntry.new(message: "Work on something", tags: ['work', 'project'])])
log.tags # => ["project", "work"]

Returns:

  • (Array<String>)


42
43
44
# File 'lib/daily_log.rb', line 42

def tags
  entries.flat_map(&:tags).uniq.sort
end