Class: Commenter::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/commenter/comment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Comment

Returns a new instance of Comment.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/commenter/comment.rb', line 7

def initialize(attributes = {})
  # Normalize input to symbols
  attrs = symbolize_keys(attributes)

  @id = attrs[:id]
  @body = attrs[:body]
  @locality = symbolize_keys(attrs[:locality] || {})
  @type = attrs[:type]
  @comments = attrs[:comments]
  @proposed_change = attrs[:proposed_change]
  @observations = attrs[:observations]
  @github = symbolize_keys(attrs[:github] || {})
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def body
  @body
end

#commentsObject

Returns the value of attribute comments.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def comments
  @comments
end

#githubObject

Returns the value of attribute github.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def github
  @github
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def id
  @id
end

#localityObject

Returns the value of attribute locality.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def locality
  @locality
end

#observationsObject

Returns the value of attribute observations.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def observations
  @observations
end

#proposed_changeObject

Returns the value of attribute proposed_change.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def proposed_change
  @proposed_change
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/commenter/comment.rb', line 5

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object



122
123
124
# File 'lib/commenter/comment.rb', line 122

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

Instance Method Details

#brief_summary(max_length = 80) ⇒ Object



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
# File 'lib/commenter/comment.rb', line 45

def brief_summary(max_length = 80)
  parts = []

  # Add locality information first
  parts << "Clause #{clause}" if clause && !clause.strip.empty?
  parts << element if element && !element.strip.empty?
  parts << "Line #{line_number}" if line_number && !line_number.strip.empty?

  locality_text = parts.join(", ")

  # Add description from comment text
  if @comments && !@comments.strip.empty?
    # Extract first sentence or truncate
    clean_text = @comments.strip.gsub(/\s+/, " ")
    first_sentence = clean_text.split(/[.!?]/).first&.strip
    description = if first_sentence && first_sentence.length < max_length
                    first_sentence
                  else
                    clean_text[0...50]
                  end

    if locality_text.empty?
      description
    else
      # Combine locality + description, respecting max_length
      combined = "#{locality_text}: #{description}"
      combined.length <= max_length ? combined : "#{locality_text}: #{description[0...(max_length - locality_text.length - 2)]}"
    end
  else
    locality_text.empty? ? "No description" : locality_text
  end
end

#clauseObject



29
30
31
# File 'lib/commenter/comment.rb', line 29

def clause
  @locality[:clause]
end

#clause=(value) ⇒ Object



33
34
35
# File 'lib/commenter/comment.rb', line 33

def clause=(value)
  @locality[:clause] = value
end

#elementObject



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

def element
  @locality[:element]
end

#element=(value) ⇒ Object



41
42
43
# File 'lib/commenter/comment.rb', line 41

def element=(value)
  @locality[:element] = value
end

#github_created_atObject



90
91
92
# File 'lib/commenter/comment.rb', line 90

def github_created_at
  @github[:created_at]
end

#github_issue_numberObject



78
79
80
# File 'lib/commenter/comment.rb', line 78

def github_issue_number
  @github[:issue_number]
end

#github_issue_urlObject



82
83
84
# File 'lib/commenter/comment.rb', line 82

def github_issue_url
  @github[:issue_url]
end

#github_statusObject



86
87
88
# File 'lib/commenter/comment.rb', line 86

def github_status
  @github[:status]
end

#github_updated_atObject



94
95
96
# File 'lib/commenter/comment.rb', line 94

def github_updated_at
  @github[:updated_at]
end

#has_github_issue?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/commenter/comment.rb', line 98

def has_github_issue?
  !@github[:issue_number].nil?
end

#line_numberObject



21
22
23
# File 'lib/commenter/comment.rb', line 21

def line_number
  @locality[:line_number]
end

#line_number=(value) ⇒ Object



25
26
27
# File 'lib/commenter/comment.rb', line 25

def line_number=(value)
  @locality[:line_number] = value
end

#to_hObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/commenter/comment.rb', line 102

def to_h
  {
    id: @id,
    body: @body,
    locality: @locality,
    type: @type,
    comments: @comments,
    proposed_change: @proposed_change,
    observations: @observations,
    github: @github.empty? ? nil : @github
  }.compact
end

#to_yaml_hObject



115
116
117
118
119
120
# File 'lib/commenter/comment.rb', line 115

def to_yaml_h
  hash = to_h
  # Remove observations if it's nil or empty
  hash.delete(:observations) if hash[:observations].nil? || hash[:observations] == ""
  stringify_keys(hash)
end