Class: LogEntry
Overview
A single log entry.
Constant Summary collapse
- PERSON_REGEX =
/\s[~@](\w+)/
Instance Attribute Summary collapse
-
#epic ⇒ Object
Represents a single entry in the work log.
-
#message ⇒ Object
Represents a single entry in the work log.
-
#tags ⇒ Object
Represents a single entry in the work log.
-
#ticket ⇒ Object
Represents a single entry in the work log.
-
#time ⇒ Object
Represents a single entry in the work log.
-
#url ⇒ Object
Represents a single entry in the work log.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#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
- #to_yaml ⇒ Object
Methods included from Hashify
Constructor Details
#initialize(params = {}) ⇒ LogEntry
Returns a new instance of LogEntry.
17 18 19 20 21 22 23 24 25 26 |
# File 'worklog/log_entry.rb', line 17 def initialize(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] end |
Instance Attribute Details
#epic ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def epic @epic end |
#message ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def @message end |
#tags ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def @tags end |
#ticket ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def ticket @ticket end |
#time ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def time @time end |
#url ⇒ Object
Represents a single entry in the work log.
15 16 17 |
# File 'worklog/log_entry.rb', line 15 def url @url end |
Instance Method Details
#==(other) ⇒ Object
90 91 92 93 |
# File 'worklog/log_entry.rb', line 90 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.
29 30 31 |
# File 'worklog/log_entry.rb', line 29 def epic? @epic == true end |
#message_string(known_people = nil) ⇒ Object
Returns the message string with formatting without the time.
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 |
# File 'worklog/log_entry.rb', line 35 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 end |
#people ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'worklog/log_entry.rb', line 68 def people # Return people that are mentioned in the entry. # People are defined as words starting with @ or ~. # Whitespaces are used to separate people. # Punctuation is not considered. # Empty array if no people are mentioned. # # @return [Array<String>] @message.scan(PERSON_REGEX).flatten.uniq.sort end |
#people? ⇒ Boolean
79 80 81 82 83 84 |
# File 'worklog/log_entry.rb', line 79 def people? # Return true if there are people in the entry. # # @return [Boolean] people.size.positive? end |
#to_yaml ⇒ Object
86 87 88 |
# File 'worklog/log_entry.rb', line 86 def to_yaml to_hash.to_yaml end |