Class: Commenter::Comment
- Inherits:
-
Object
- Object
- Commenter::Comment
- Defined in:
- lib/commenter/comment.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#comment_type ⇒ Object
Returns the value of attribute comment_type.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#created_date ⇒ Object
Returns the value of attribute created_date.
-
#feedbacks ⇒ Object
Returns the value of attribute feedbacks.
-
#github ⇒ Object
Returns the value of attribute github.
-
#id ⇒ Object
Returns the value of attribute id.
-
#locality ⇒ Object
Returns the value of attribute locality.
-
#motivation ⇒ Object
Returns the value of attribute motivation.
-
#observations ⇒ Object
Returns the value of attribute observations.
-
#proposed_change ⇒ Object
Returns the value of attribute proposed_change.
-
#resolution_date ⇒ Object
Returns the value of attribute resolution_date.
-
#resolution_status ⇒ Object
Returns the value of attribute resolution_status.
-
#stage_code ⇒ Object
Returns the value of attribute stage_code.
-
#type ⇒ Object
Returns the value of attribute type.
-
#user_name ⇒ Object
Returns the value of attribute user_name.
Class Method Summary collapse
Instance Method Summary collapse
- #brief_summary(max_length = 80) ⇒ Object
- #clause ⇒ Object
- #clause=(value) ⇒ Object
- #element ⇒ Object
- #element=(value) ⇒ Object
- #expand_comment_type(type) ⇒ Object
- #github_created_at ⇒ Object
- #github_issue_number ⇒ Object
- #github_issue_url ⇒ Object
- #github_status ⇒ Object
- #github_updated_at ⇒ Object
- #has_github_issue? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Comment
constructor
A new instance of Comment.
- #line_number ⇒ Object
- #line_number=(value) ⇒ Object
- #to_h ⇒ Object
- #to_yaml_h ⇒ Object
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
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def body @body end |
#comment_type ⇒ Object
Returns the value of attribute comment_type.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def comment_type @comment_type end |
#comments ⇒ Object
Returns the value of attribute comments.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def comments @comments end |
#created_date ⇒ Object
Returns the value of attribute created_date.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def created_date @created_date end |
#feedbacks ⇒ Object
Returns the value of attribute feedbacks.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def feedbacks @feedbacks end |
#github ⇒ Object
Returns the value of attribute github.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def github @github end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def id @id end |
#locality ⇒ Object
Returns the value of attribute locality.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def locality @locality end |
#motivation ⇒ Object
Returns the value of attribute motivation.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def motivation @motivation end |
#observations ⇒ Object
Returns the value of attribute observations.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def observations @observations end |
#proposed_change ⇒ Object
Returns the value of attribute proposed_change.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def proposed_change @proposed_change end |
#resolution_date ⇒ Object
Returns the value of attribute resolution_date.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def resolution_date @resolution_date end |
#resolution_status ⇒ Object
Returns the value of attribute resolution_status.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def resolution_status @resolution_status end |
#stage_code ⇒ Object
Returns the value of attribute stage_code.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def stage_code @stage_code end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def type @type end |
#user_name ⇒ Object
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 |
#clause ⇒ Object
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 |
#element ⇒ Object
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 (type) CommentType.full_name(type) end |
#github_created_at ⇒ Object
106 107 108 |
# File 'lib/commenter/comment.rb', line 106 def github_created_at @github[:created_at] end |
#github_issue_number ⇒ Object
94 95 96 |
# File 'lib/commenter/comment.rb', line 94 def github_issue_number @github[:issue_number] end |
#github_issue_url ⇒ Object
98 99 100 |
# File 'lib/commenter/comment.rb', line 98 def github_issue_url @github[:issue_url] end |
#github_status ⇒ Object
102 103 104 |
# File 'lib/commenter/comment.rb', line 102 def github_status @github[:status] end |
#github_updated_at ⇒ Object
110 111 112 |
# File 'lib/commenter/comment.rb', line 110 def github_updated_at @github[:updated_at] end |
#has_github_issue? ⇒ Boolean
114 115 116 |
# File 'lib/commenter/comment.rb', line 114 def has_github_issue? !@github[:issue_number].nil? end |
#line_number ⇒ Object
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_h ⇒ Object
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_h ⇒ Object
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 |