Class: Worklog::LogEntry

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

Overview

A single log entry in a DailyLog.

See Also:

Constant Summary collapse

PERSON_REGEX =
/(?:\s|^)[~@](\w+)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hashify

#to_hash

Constructor Details

#initialize(params = {}) ⇒ LogEntry

Returns a new instance of LogEntry.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/log_entry.rb', line 39

def initialize(params = {})
  # key can be nil. This is needed for backwards compatibility with older log entries.
  @key = params[:key]
  @source = params[:source] || 'manual'
  @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
  # If tags are nil, set to empty array.
  # This is similar to the CLI default value.
  @tags = params[:tags] || []
  @ticket = params[:ticket]
  @url = params[:url] || ''
  @epic = params[:epic]
  @message = params[:message]
  @project = params[:project]

  # Back reference to the day
  @day = params[:day] || nil
end

Instance Attribute Details

#dayObject (readonly)

Returns the value of attribute day.



37
38
39
# File 'lib/log_entry.rb', line 37

def day
  @day
end

#epicBoolean

Returns whether the log entry is an epic.

Returns:

  • (Boolean)

    whether the log entry is an epic.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#keyString

Returns the unique key of the log entry. The key is generated based on the time and message.

Returns:

  • (String)

    the unique key of the log entry. The key is generated based on the time and message.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#messageString

Returns the message of the log entry.

Returns:

  • (String)

    the message of the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#projectString

Returns the project associated with the log entry.

Returns:

  • (String)

    the project associated with the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#sourceString

Returns the source of the log entry, e.g., ‘github’, ‘manual’, etc.

Returns:

  • (String)

    the source of the log entry, e.g., ‘github’, ‘manual’, etc.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#tagsArray<String>

Returns the tags associated with the log entry.

Returns:

  • (Array<String>)

    the tags associated with the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#ticketString

Returns the ticket associated with the log entry.

Returns:

  • (String)

    the ticket associated with the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#timeTime

Returns the date and time of the log entry.

Returns:

  • (Time)

    the date and time of the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

#urlString

Returns the URL associated with the log entry.

Returns:

  • (String)

    the URL associated with the log entry.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/log_entry.rb', line 30

class LogEntry
  PERSON_REGEX = /(?:\s|^)[~@](\w+)/

  include Hashify

  attr_accessor :key, :source, :time, :tags, :ticket, :url, :epic, :message, :project

  attr_reader :day

  def initialize(params = {})
    # key can be nil. This is needed for backwards compatibility with older log entries.
    @key = params[:key]
    @source = params[:source] || 'manual'
    @time = params[:time].is_a?(String) ? Time.parse(params[:time]) : params[:time]
    # If tags are nil, set to empty array.
    # This is similar to the CLI default value.
    @tags = params[:tags] || []
    @ticket = params[:ticket]
    @url = params[:url] || ''
    @epic = params[:epic]
    @message = params[:message]
    @project = params[:project]

    # Back reference to the day
    @day = params[:day] || nil
  end

  # Returns true if the entry is an epic, false otherwise.
  # @return [Boolean]
  def epic?
    @epic == true
  end

  # Returns the message string with formatting without the time.
  # @param known_people Hash[String, Person] A hash of people with their handles as keys.
  # @param formatter [BaseFormatter] the formatter to use for formatting the message. If nil, a default
  # ConsoleFormatter is used.
  # @return [String] the formatted message string
  def message_string(known_people = nil, formatter = nil)
    formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
    formatter.format(self)
  end

  # Return people that are mentioned in the entry. People are defined as character sequences
  # starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored.
  # Empty set if no people are mentioned.
  # @return [Set<String>]
  def people
    @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
  end

  # Return true if there are people in the entry.
  #
  # @return [Boolean]
  def people?
    people.size.positive?
  end

  # Create a LogEntry from a hash with symbolized keys
  # This is an alias for the constructor and here for consistency with other classes.
  #
  # @param hash [Hash] the hash to convert
  # @return [LogEntry] the created LogEntry object
  def self.from_hash(hash)
    new(**hash)
  end

  # Convert the log entry to YAML format.
  # @return [String] the YAML representation of the log entry.
  def to_yaml
    to_hash.to_yaml
  end

  # Compare two log entries for equality.
  #
  # @param other [LogEntry] The other log entry to compare against.
  # @return [Boolean] True if the log entries are equal, false otherwise.
  def ==(other)
    time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
      epic == other.epic && message == other.message
  end
end

Class Method Details

.from_hash(hash) ⇒ LogEntry

Create a LogEntry from a hash with symbolized keys This is an alias for the constructor and here for consistency with other classes.

Parameters:

  • hash (Hash)

    the hash to convert

Returns:

  • (LogEntry)

    the created LogEntry object



93
94
95
# File 'lib/log_entry.rb', line 93

def self.from_hash(hash)
  new(**hash)
end

Instance Method Details

#==(other) ⇒ Boolean

Compare two log entries for equality.

Parameters:

  • other (LogEntry)

    The other log entry to compare against.

Returns:

  • (Boolean)

    True if the log entries are equal, false otherwise.



107
108
109
110
# File 'lib/log_entry.rb', line 107

def ==(other)
  time == other.time && tags == other.tags && ticket == other.ticket && url == other.url &&
    epic == other.epic && message == other.message
end

#epic?Boolean

Returns true if the entry is an epic, false otherwise.

Returns:

  • (Boolean)


59
60
61
# File 'lib/log_entry.rb', line 59

def epic?
  @epic == true
end

#message_string(known_people = nil, formatter = nil) ⇒ String

Returns the message string with formatting without the time. ConsoleFormatter is used.

Parameters:

  • known_people (defaults to: nil)

    Hash[String, Person] A hash of people with their handles as keys.

  • formatter (BaseFormatter) (defaults to: nil)

    the formatter to use for formatting the message. If nil, a default

Returns:

  • (String)

    the formatted message string



68
69
70
71
# File 'lib/log_entry.rb', line 68

def message_string(known_people = nil, formatter = nil)
  formatter ||= LogEntryFormatters::ConsoleFormatter.new(known_people)
  formatter.format(self)
end

#peopleSet<String>

Return people that are mentioned in the entry. People are defined as character sequences starting with @ or ~. Whitespaces are used to separate people. Punctuation is ignored. Empty set if no people are mentioned.

Returns:

  • (Set<String>)


77
78
79
# File 'lib/log_entry.rb', line 77

def people
  @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set
end

#people?Boolean

Return true if there are people in the entry.

Returns:

  • (Boolean)


84
85
86
# File 'lib/log_entry.rb', line 84

def people?
  people.size.positive?
end

#to_yamlString

Convert the log entry to YAML format.

Returns:

  • (String)

    the YAML representation of the log entry.



99
100
101
# File 'lib/log_entry.rb', line 99

def to_yaml
  to_hash.to_yaml
end