Class: Cease::Eviction::Comment
- Inherits:
-
Object
- Object
- Cease::Eviction::Comment
- Extended by:
- Forwardable
- Includes:
- Comparable, DOTIW::Methods
- Defined in:
- lib/cease/eviction/comment.rb
Constant Summary collapse
- OPEN_COMMENT_REGEX =
/ \[cease\]\s # prefix (.+?) # non-greedy date and time (:?\s*) # optional seperator (\{.*?\})? # optional options $ # extend non-greedy matchers to end of line /x.freeze
- CLOSE_COMMENT_REGEX =
/\[\/cease\]/.freeze
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #close_comment? ⇒ Boolean
- #date_time ⇒ Object
-
#initialize(comment:, source: nil) ⇒ Comment
constructor
A new instance of Comment.
- #last_commit_date ⇒ Object
- #nested_in?(other) ⇒ Boolean
- #overdue? ⇒ Boolean
- #parse ⇒ Object
- #past_due_description ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(comment:, source: nil) ⇒ Comment
Returns a new instance of Comment.
34 35 36 37 38 |
# File 'lib/cease/eviction/comment.rb', line 34 def initialize(comment:, source: nil) @comment = comment @date_time, @seperator, @options = scanned_comment @source = source end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
93 94 95 |
# File 'lib/cease/eviction/comment.rb', line 93 def comment @comment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
93 94 95 |
# File 'lib/cease/eviction/comment.rb', line 93 def @options end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
93 94 95 |
# File 'lib/cease/eviction/comment.rb', line 93 def source @source end |
Class Method Details
.close_comment?(comment) ⇒ Boolean
27 28 29 30 |
# File 'lib/cease/eviction/comment.rb', line 27 def self.close_comment?(comment) return false unless comment !!(comment.text =~ CLOSE_COMMENT_REGEX) end |
Instance Method Details
#<=>(other) ⇒ Object
79 80 81 |
# File 'lib/cease/eviction/comment.rb', line 79 def <=>(other) other.loc.expression.begin_pos <=> loc.expression.begin_pos end |
#close_comment? ⇒ Boolean
48 49 50 |
# File 'lib/cease/eviction/comment.rb', line 48 def close_comment? self.class.close_comment?(comment) end |
#date_time ⇒ Object
44 45 46 |
# File 'lib/cease/eviction/comment.rb', line 44 def date_time Command::DateTime.new(self, @date_time, @options) end |
#last_commit_date ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/cease/eviction/comment.rb', line 52 def last_commit_date return unless source line = loc.line search = "-L #{line},#{line}:#{source.to_s}" Git.log.object(search)&.first&.date end |
#nested_in?(other) ⇒ Boolean
83 84 85 |
# File 'lib/cease/eviction/comment.rb', line 83 def nested_in?(other) other.loc.expression.end_pos > loc.expression.begin_pos end |
#overdue? ⇒ Boolean
72 73 74 75 76 77 |
# File 'lib/cease/eviction/comment.rb', line 72 def overdue? return false if close_comment? return false unless date_time.valid? date_time.tz.to_local(DateTime.now) >= date_time.parsed_in_timezone end |
#parse ⇒ Object
40 41 42 |
# File 'lib/cease/eviction/comment.rb', line 40 def parse scanned_comment end |
#past_due_description ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cease/eviction/comment.rb', line 60 def past_due_description return unless overdue? dotiw = distance_of_time_in_words( date_time.tz.to_local(DateTime.now), date_time.parsed_in_timezone, highest_measures: 1 ) "Overdue by roughly #{dotiw}" end |
#valid? ⇒ Boolean
87 88 89 90 91 |
# File 'lib/cease/eviction/comment.rb', line 87 def valid? return false unless comment return true if close_comment? parse.any? end |