Class: Commenter::CommentSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/commenter/comment_sheet.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#commentsObject

Returns the value of attribute comments.



7
8
9
# File 'lib/commenter/comment_sheet.rb', line 7

def comments
  @comments
end

#dateObject

Returns the value of attribute date.



7
8
9
# File 'lib/commenter/comment_sheet.rb', line 7

def date
  @date
end

#documentObject

Returns the value of attribute document.



7
8
9
# File 'lib/commenter/comment_sheet.rb', line 7

def document
  @document
end

#projectObject

Returns the value of attribute project.



7
8
9
# File 'lib/commenter/comment_sheet.rb', line 7

def project
  @project
end

#stageObject

Returns the value of attribute stage.



7
8
9
# File 'lib/commenter/comment_sheet.rb', line 7

def stage
  @stage
end

#versionObject

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_hObject



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_hObject



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