Class: Commenter::Comment
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Commenter::Comment
- Defined in:
- lib/commenter/comment.rb
Overview
A single comment on a reviewed document. (De)serialization is declared with lutaml-model; the only custom mapping logic is the type expansion (short codes to full names) and empty-observation omission, both at the YAML boundary.
Instance Method Summary collapse
- #brief_summary(max_length = 60) ⇒ 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
- #line_number ⇒ Object
- #line_number=(value) ⇒ Object
- #observations_from_yaml(model, value) ⇒ Object
- #observations_to_yaml(model, doc) ⇒ Object
- #record_github_issue(issue_number:, issue_url:, status:, created_at: nil) ⇒ Object
- #to_h ⇒ Object (also: #to_yaml_h)
- #type_from_yaml(model, value) ⇒ Object
- #type_to_yaml(model, doc) ⇒ Object
Instance Method Details
#brief_summary(max_length = 60) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/commenter/comment.rb', line 103 def brief_summary(max_length = 60) description = comments.to_s.split(/[.!?\n]/).map(&:strip).reject(&:empty?).first.to_s locality_text = format_locality if description.empty? locality_text.empty? ? "No description" : locality_text elsif locality_text.empty? combined = description combined.length <= max_length ? combined : "#{combined[0...(max_length - 3)]}..." else combined = "#{locality_text}: #{description}" combined.length <= max_length ? combined : "#{locality_text}: #{description[0...(max_length - locality_text.length - 2)]}" end end |
#clause ⇒ Object
85 86 87 |
# File 'lib/commenter/comment.rb', line 85 def clause locality&.clause end |
#clause=(value) ⇒ Object
89 90 91 92 |
# File 'lib/commenter/comment.rb', line 89 def clause=(value) self.locality = CommentLocality.new if locality.nil? locality.clause = value end |
#element ⇒ Object
94 95 96 |
# File 'lib/commenter/comment.rb', line 94 def element locality&.element end |
#element=(value) ⇒ Object
98 99 100 101 |
# File 'lib/commenter/comment.rb', line 98 def element=(value) self.locality = CommentLocality.new if locality.nil? locality.element = value end |
#expand_comment_type(type) ⇒ Object
66 67 68 |
# File 'lib/commenter/comment.rb', line 66 def (type) CommentType.full_name(type) end |
#github_created_at ⇒ Object
130 131 132 |
# File 'lib/commenter/comment.rb', line 130 def github_created_at github&.created_at end |
#github_issue_number ⇒ Object
118 119 120 |
# File 'lib/commenter/comment.rb', line 118 def github_issue_number github&.issue_number end |
#github_issue_url ⇒ Object
122 123 124 |
# File 'lib/commenter/comment.rb', line 122 def github_issue_url github&.issue_url end |
#github_status ⇒ Object
126 127 128 |
# File 'lib/commenter/comment.rb', line 126 def github_status github&.status end |
#github_updated_at ⇒ Object
134 135 136 |
# File 'lib/commenter/comment.rb', line 134 def github_updated_at github&.updated_at end |
#has_github_issue? ⇒ Boolean
138 139 140 |
# File 'lib/commenter/comment.rb', line 138 def has_github_issue? !github&.issue_number.nil? end |
#line_number ⇒ Object
76 77 78 |
# File 'lib/commenter/comment.rb', line 76 def line_number locality&.line_number end |
#line_number=(value) ⇒ Object
80 81 82 83 |
# File 'lib/commenter/comment.rb', line 80 def line_number=(value) self.locality = CommentLocality.new if locality.nil? locality.line_number = value end |
#observations_from_yaml(model, value) ⇒ Object
58 59 60 |
# File 'lib/commenter/comment.rb', line 58 def observations_from_yaml(model, value) model.observations = value.to_s.empty? ? nil : value end |
#observations_to_yaml(model, doc) ⇒ Object
62 63 64 |
# File 'lib/commenter/comment.rb', line 62 def observations_to_yaml(model, doc) doc["observations"] = model.observations if model.observations && !model.observations.empty? end |
#record_github_issue(issue_number:, issue_url:, status:, created_at: nil) ⇒ Object
142 143 144 145 |
# File 'lib/commenter/comment.rb', line 142 def record_github_issue(issue_number:, issue_url:, status:, created_at: nil) self.github = GithubInfo.new(issue_number: issue_number, issue_url: issue_url, status: status, created_at: created_at) end |
#to_h ⇒ Object Also known as: to_yaml_h
70 71 72 |
# File 'lib/commenter/comment.rb', line 70 def to_h Comment.to_hash(self) end |
#type_from_yaml(model, value) ⇒ Object
50 51 52 |
# File 'lib/commenter/comment.rb', line 50 def type_from_yaml(model, value) model.type = CommentType.full_name(value) end |
#type_to_yaml(model, doc) ⇒ Object
54 55 56 |
# File 'lib/commenter/comment.rb', line 54 def type_to_yaml(model, doc) doc["type"] = model.type if model.type && !model.type.empty? end |