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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/commenter/comment.rb', line 9

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

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

  # OSD-specific fields
  @user_name = attrs[:user_name]
  @comment_type = attrs[:comment_type]
  @resolution_status = attrs[:resolution_status]
  @resolution_date = attrs[:resolution_date]
  @feedbacks = attrs[:feedbacks]
  @motivation = attrs[:motivation]
  @created_date = attrs[:created_date]
  @stage_code = attrs[:stage_code]
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

#comment_typeObject

Returns the value of attribute comment_type.



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

def comment_type
  @comment_type
end

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#created_dateObject

Returns the value of attribute created_date.



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

def created_date
  @created_date
end

#feedbacksObject

Returns the value of attribute feedbacks.



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

def feedbacks
  @feedbacks
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

#motivationObject

Returns the value of attribute motivation.



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

def motivation
  @motivation
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

#resolution_dateObject

Returns the value of attribute resolution_date.



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

def resolution_date
  @resolution_date
end

#resolution_statusObject

Returns the value of attribute resolution_status.



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

def resolution_status
  @resolution_status
end

#stage_codeObject

Returns the value of attribute stage_code.



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

def stage_code
  @stage_code
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#user_nameObject

Returns the value of attribute user_name.



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

def user_name
  @user_name
end

Class Method Details

.from_hash(hash) ⇒ Object



146
147
148
# File 'lib/commenter/comment.rb', line 146

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

Instance Method Details

#brief_summary(max_length = 80) ⇒ Object



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

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



45
46
47
# File 'lib/commenter/comment.rb', line 45

def clause
  @locality[:clause]
end

#clause=(value) ⇒ Object



49
50
51
# File 'lib/commenter/comment.rb', line 49

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

#elementObject



53
54
55
# File 'lib/commenter/comment.rb', line 53

def element
  @locality[:element]
end

#element=(value) ⇒ Object



57
58
59
# File 'lib/commenter/comment.rb', line 57

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

#expand_comment_type(type) ⇒ Object



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

def expand_comment_type(type)
  CommentType.full_name(type)
end

#github_created_atObject



106
107
108
# File 'lib/commenter/comment.rb', line 106

def github_created_at
  @github[:created_at]
end

#github_issue_numberObject



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

def github_issue_number
  @github[:issue_number]
end

#github_issue_urlObject



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

def github_issue_url
  @github[:issue_url]
end

#github_statusObject



102
103
104
# File 'lib/commenter/comment.rb', line 102

def github_status
  @github[:status]
end

#github_updated_atObject



110
111
112
# File 'lib/commenter/comment.rb', line 110

def github_updated_at
  @github[:updated_at]
end

#has_github_issue?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/commenter/comment.rb', line 114

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

#line_numberObject



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

def line_number
  @locality[:line_number]
end

#line_number=(value) ⇒ Object



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

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

#to_hObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/commenter/comment.rb', line 118

def to_h
  {
    id: @id,
    body: @body,
    locality: @locality,
    type: @type,
    comments: @comments,
    proposed_change: @proposed_change,
    observations: @observations,
    user_name: @user_name,
    comment_type: @comment_type,
    resolution_status: @resolution_status,
    resolution_date: @resolution_date,
    feedbacks: @feedbacks,
    motivation: @motivation,
    created_date: @created_date,
    stage_code: @stage_code,
    github: @github.empty? ? nil : @github
  }.compact
end

#to_yaml_hObject



139
140
141
142
143
144
# File 'lib/commenter/comment.rb', line 139

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