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.new(parent: excel_comments).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 |
# 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) file = path_to_folder + "xl/worksheets/_rels/#{file_name}.rels" return nil unless File.exist?(file) relationships = Relationships.parse_rels(file) target = relationships.target_by_type('comment') return if target.nil? comment_file = "#{OOXMLDocumentObject.path_to_folder}/#{OOXMLDocumentObject.root_subfolder}/#{target.gsub('..', '')}" ExcelComments.parse(comment_file) end |