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.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#github ⇒ Object
Returns the value of attribute github.
-
#id ⇒ Object
Returns the value of attribute id.
-
#locality ⇒ Object
Returns the value of attribute locality.
-
#observations ⇒ Object
Returns the value of attribute observations.
-
#proposed_change ⇒ Object
Returns the value of attribute proposed_change.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #brief_summary(max_length = 80) ⇒ Object
- #clause ⇒ Object
- #clause=(value) ⇒ Object
- #element ⇒ Object
- #element=(value) ⇒ 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.
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
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def body @body end |
#comments ⇒ Object
Returns the value of attribute comments.
5 6 7 |
# File 'lib/commenter/comment.rb', line 5 def comments @comments 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 |
#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 |
#type ⇒ Object
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 |
#clause ⇒ Object
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 |
#element ⇒ Object
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_at ⇒ Object
90 91 92 |
# File 'lib/commenter/comment.rb', line 90 def github_created_at @github[:created_at] end |
#github_issue_number ⇒ Object
78 79 80 |
# File 'lib/commenter/comment.rb', line 78 def github_issue_number @github[:issue_number] end |
#github_issue_url ⇒ Object
82 83 84 |
# File 'lib/commenter/comment.rb', line 82 def github_issue_url @github[:issue_url] end |
#github_status ⇒ Object
86 87 88 |
# File 'lib/commenter/comment.rb', line 86 def github_status @github[:status] end |
#github_updated_at ⇒ Object
94 95 96 |
# File 'lib/commenter/comment.rb', line 94 def github_updated_at @github[:updated_at] end |
#has_github_issue? ⇒ Boolean
98 99 100 |
# File 'lib/commenter/comment.rb', line 98 def has_github_issue? !@github[:issue_number].nil? end |
#line_number ⇒ Object
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_h ⇒ Object
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_h ⇒ Object
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 |