class OoxmlParser::Inserted

Class for parsing ‘w:ins` tag - Inserted Run Content

Attributes

author[RW]

@return [String] author of insert

date[RW]

@return [Date] date of insert

id[RW]

@return [Integer] id of inserted

run[RW]

@return [ParagraphRun] inserted run

user_id[RW]

@return [String] id of user

Public Instance Methods

parse(node) click to toggle source

Parse Inserted object @param node [Nokogiri::XML:Element] node to parse @return [Inserted] result of parsing

# File lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/inserted.rb, line 22
def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'id'
      @id = value.value.to_i
    when 'author'
      @author = value.value.to_s
    when 'date'
      @date = parse_date(value.value.to_s)
    when 'oouserid'
      @user_id = value.value.to_s
    end
  end

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'r'
      @run = ParagraphRun.new(parent: self).parse(node_child)
    end
  end
  self
end

Private Instance Methods

parse_date(value) click to toggle source

Parse date and handle incorrect dates @param value [Sting] value of date @return [DateTime, String] if date correct or incorrect

# File lib/ooxml_parser/docx_parser/document_structure/docx_paragraph/inserted.rb, line 50
def parse_date(value)
  DateTime.parse(value)
rescue ArgumentError
  warn "Date #{value} is incorrect format"
  value
end