Class: OOXML::Excel::Comments

Inherits:
Object
  • Object
show all
Defined in:
lib/ooxml_excel/comments.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(comments) ⇒ Comments

Returns a new instance of Comments.



6
7
8
# File 'lib/ooxml_excel/comments.rb', line 6

def initialize(comments)
  @comments = comments
end

Instance Attribute Details

#commentsObject (readonly)

Returns the value of attribute comments.



4
5
6
# File 'lib/ooxml_excel/comments.rb', line 4

def comments
  @comments
end

Class Method Details

.load_from_stream(comment_xml) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ooxml_excel/comments.rb', line 14

def self.load_from_stream(comment_xml)
  comment_xml =Nokogiri.XML(comment_xml).remove_namespaces!

  comments = comment_xml.xpath("//comments/commentList/comment").map do |comment_node|
    comment_text_node = comment_node.xpath('./text/r/t')

    value = if comment_text_node.is_a?(Array)
      comment_text_node.map { |comment_text_node| comment_text_node.text }.join('')
    else
      comment_text_node.text
    end

    # value = (comment_node.xpath('./text/r/t').last || comment_node.at_xpath('./text/r/t') || comment_node.at_xpath('./text/t')).text
    id = comment_node.attributes["ref"].to_s
    [id, value]
  end.to_h
  new(comments)
end

Instance Method Details

#[](id) ⇒ Object



10
11
12
# File 'lib/ooxml_excel/comments.rb', line 10

def [](id)
  @comments[id]
end