Class: Cease::Eviction::Comment

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#commentObject (readonly)

Returns the value of attribute comment.



93
94
95
# File 'lib/cease/eviction/comment.rb', line 93

def comment
  @comment
end

#optionsObject (readonly)

Returns the value of attribute options.



93
94
95
# File 'lib/cease/eviction/comment.rb', line 93

def options
  @options
end

#sourceObject (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

Returns:

  • (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

Returns:

  • (Boolean)


48
49
50
# File 'lib/cease/eviction/comment.rb', line 48

def close_comment?
  self.class.close_comment?(comment)
end

#date_timeObject



44
45
46
# File 'lib/cease/eviction/comment.rb', line 44

def date_time
   Command::DateTime.new(self, @date_time, @options)
end

#last_commit_dateObject



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

Returns:

  • (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

Returns:

  • (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

#parseObject



40
41
42
# File 'lib/cease/eviction/comment.rb', line 40

def parse
  scanned_comment
end

#past_due_descriptionObject



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

Returns:

  • (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