Class: OoxmlParser::ExcelComments
- Inherits:
-
Object
- Object
- OoxmlParser::ExcelComments
- Defined in:
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb
Instance Attribute Summary collapse
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#comments ⇒ Object
Returns the value of attribute comments.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(authors = [], comments = []) ⇒ ExcelComments
constructor
A new instance of ExcelComments.
Constructor Details
#initialize(authors = [], comments = []) ⇒ ExcelComments
Returns a new instance of ExcelComments.
7 8 9 10 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb', line 7 def initialize( = [], comments = []) @authors = @comments = comments end |
Instance Attribute Details
#authors ⇒ Object
Returns the value of attribute authors.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb', line 5 def @authors end |
#comments ⇒ Object
Returns the value of attribute comments.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb', line 5 def comments @comments end |
Class Method Details
.parse(file) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb', line 12 def self.parse(file) doc = Nokogiri::XML(File.open(file)) excel_comments = ExcelComments.new comments_node = doc.search('//xmlns:comments').first comments_node.xpath('*').each do |comments_node_child| case comments_node_child.name when 'authors' comments_node_child.xpath('xmlns:author').each do || excel_comments. << .text end when 'commentList' comments_node_child.xpath('xmlns:comment').each do |comment_node| excel_comments.comments << ExcelComment.parse(comment_node) end end end excel_comments end |
.parse_file(file_name, path_to_folder) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/excel_comments.rb', line 31 def self.parse_file(file_name, path_to_folder) path_to_comments_xml = '' return nil unless File.exist?(path_to_folder + "xl/worksheets/_rels/#{file_name}.rels") relationships = XmlSimple.xml_in(File.open(path_to_folder + "xl/worksheets/_rels/#{file_name}.rels")) if relationships['Relationship'] relationships['Relationship'].each do |relationship| path_to_comments_xml = path_to_folder + 'xl/' + relationship['Target'].gsub('..', '') if File.basename(relationship['Target']).include?('comment') end end ExcelComments.parse(path_to_comments_xml) unless path_to_comments_xml == '' end |