Class: Commenter::CommentSheet
- Inherits:
-
Object
- Object
- Commenter::CommentSheet
- Defined in:
- lib/commenter/comment_sheet.rb
Instance Attribute Summary collapse
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#date ⇒ Object
Returns the value of attribute date.
-
#document ⇒ Object
Returns the value of attribute document.
-
#project ⇒ Object
Returns the value of attribute project.
-
#stage ⇒ Object
Returns the value of attribute stage.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #add_comment(comment) ⇒ Object
-
#initialize(attributes = {}) ⇒ CommentSheet
constructor
A new instance of CommentSheet.
- #to_h ⇒ Object
- #to_yaml_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ CommentSheet
Returns a new instance of CommentSheet.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/commenter/comment_sheet.rb', line 9 def initialize(attributes = {}) # Normalize input to symbols attrs = symbolize_keys(attributes) @version = attrs[:version] || "2012-03" @date = attrs[:date] @document = attrs[:document] @project = attrs[:project] @stage = attrs[:stage] @comments = (attrs[:comments] || []).map { |c| c.is_a?(Comment) ? c : Comment.from_hash(c) } end |
Instance Attribute Details
#comments ⇒ Object
Returns the value of attribute comments.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def comments @comments end |
#date ⇒ Object
Returns the value of attribute date.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def date @date end |
#document ⇒ Object
Returns the value of attribute document.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def document @document end |
#project ⇒ Object
Returns the value of attribute project.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def project @project end |
#stage ⇒ Object
Returns the value of attribute stage.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def stage @stage end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/commenter/comment_sheet.rb', line 7 def version @version end |
Class Method Details
.from_hash(hash) ⇒ Object
40 41 42 |
# File 'lib/commenter/comment_sheet.rb', line 40 def self.from_hash(hash) new(hash) end |
Instance Method Details
#add_comment(comment) ⇒ Object
21 22 23 |
# File 'lib/commenter/comment_sheet.rb', line 21 def add_comment(comment) @comments << (comment.is_a?(Comment) ? comment : Comment.from_hash(comment)) end |
#to_h ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/commenter/comment_sheet.rb', line 25 def to_h { version: @version, date: @date, document: @document, project: @project, stage: @stage, comments: @comments.map(&:to_h) } end |
#to_yaml_h ⇒ Object
36 37 38 |
# File 'lib/commenter/comment_sheet.rb', line 36 def to_yaml_h stringify_keys(to_h.merge(comments: @comments.map(&:to_yaml_h))) end |