Class: Worklog::LogEntry
Overview
A single log entry in a DailyLog.
Constant Summary collapse
- PERSON_REGEX =
/(?:\s|^)[~@](\w+)/
Instance Attribute Summary collapse
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#epic ⇒ Boolean
Whether the log entry is an epic.
-
#key ⇒ String
The unique key of the log entry.
-
#message ⇒ String
The message of the log entry.
-
#project ⇒ String
The project associated with the log entry.
-
#tags ⇒ Array<String>
The tags associated with the log entry.
-
#ticket ⇒ String
The ticket associated with the log entry.
-
#time ⇒ Time
The date and time of the log entry.
-
#url ⇒ String
The URL associated with the log entry.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare two log entries for equality.
-
#epic? ⇒ Boolean
Returns true if the entry is an epic, false otherwise.
-
#initialize(params = {}) ⇒ LogEntry
constructor
A new instance of LogEntry.
-
#message_string(known_people = nil) ⇒ Object
Returns the message string with formatting without the time.
- #people ⇒ Object
-
#people? ⇒ Boolean
Return true if there are people in the entry.
-
#to_yaml ⇒ Object
Convert the log entry to YAML format.
Methods included from Hashify
Constructor Details
#initialize(params = {}) ⇒ LogEntry
Returns a new instance of LogEntry.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/log_entry.rb', line 36 def initialize(params = {}) # key can be nil. This is needed for backwards compatibility with older log entries. @key = params[:key] @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
#day ⇒ Object (readonly)
Returns the value of attribute day.
34 35 36 |
# File 'lib/log_entry.rb', line 34 def day @day end |
#epic ⇒ Boolean
Returns whether the log entry is an epic.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#key ⇒ String
Returns the unique key of the log entry. The key is generated based on the time and message.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#message ⇒ String
Returns the message of the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#project ⇒ String
Returns the project associated with the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#tags ⇒ Array<String>
Returns the tags associated with the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#ticket ⇒ String
Returns the ticket associated with the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#time ⇒ Time
Returns the date and time of the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end end |
#url ⇒ String
Returns the URL associated with the log entry.
27 28 29 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/log_entry.rb', line 27 class LogEntry PERSON_REGEX = /(?:\s|^)[~@](\w+)/ include Hashify attr_accessor :key, :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] @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. def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end def people # 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>] @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. 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 && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. 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.
116 117 118 |
# File 'lib/log_entry.rb', line 116 def self.from_hash(hash) new(**hash) end |
Instance Method Details
#==(other) ⇒ Boolean
Compare two log entries for equality.
129 130 131 132 |
# File 'lib/log_entry.rb', line 129 def ==(other) time == other.time && == other. && ticket == other.ticket && url == other.url && epic == other.epic && == other. end |
#epic? ⇒ Boolean
Returns true if the entry is an epic, false otherwise.
55 56 57 |
# File 'lib/log_entry.rb', line 55 def epic? @epic == true end |
#message_string(known_people = nil) ⇒ Object
Returns the message string with formatting without the time.
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 |
# File 'lib/log_entry.rb', line 61 def (known_people = nil) # replace all mentions of people with their names. msg = @message.dup people.each do |person| next unless known_people && known_people[person] msg.gsub!(/[~@]#{person}/) do |match| s = '' s += ' ' if match[0] == ' ' s += "#{Rainbow(known_people[person].name).underline} (~#{person})" if known_people && known_people[person] s end end s = '' s += if epic Rainbow("[EPIC] #{msg}").bg(:white).fg(:black) else msg end s += " [#{Rainbow(@ticket).fg(:blue)}]" if @ticket # Add tags in brackets if defined. s += ' [' + @tags.map { |tag| "#{tag}" }.join(', ') + ']' if @tags && @tags.size > 0 # Add URL in brackets if defined. s += " [#{@url}]" if @url && @url != '' s += " [#{@project}]" if @project && @project != '' s end |
#people ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/log_entry.rb', line 96 def people # 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>] @message.scan(PERSON_REGEX).flatten.uniq.sort.to_set end |
#people? ⇒ Boolean
Return true if there are people in the entry.
107 108 109 |
# File 'lib/log_entry.rb', line 107 def people? people.size.positive? end |
#to_yaml ⇒ Object
Convert the log entry to YAML format.
121 122 123 |
# File 'lib/log_entry.rb', line 121 def to_yaml to_hash.to_yaml end |