class PnoteClient::Documents::Hml::Paragraph

Attributes

elements[R]
endnote_paragraphs[R]
footnote_paragraphs[R]
shape_id[R]
style_id[R]

Public Class Methods

from_tag(pg_tag) click to toggle source

Textable Element

# File lib/pnote_client/documents/hml/paragraph.rb, line 13
def self.from_tag(pg_tag)
  paragraph = self.new(
    style_id: pg_tag['Style'],
    shape_id: pg_tag['ParaShape']
  )

  # Add Elements
  children = pg_tag.xpath("TEXT/CHAR|TEXT/EQUATION|TEXT/ENDNOTE|TEXT/FOOTNOTE|TEXT/TABLE|TEXT/RECTANGLE|TEXT/PICTURE/IMAGE")
  children.each do |child|
    if child.name == 'CHAR'
      paragraph.add_element(Char.from_tag(child))
    elsif child.name == 'EQUATION'
      paragraph.add_element(Equation.from_tag(child))
    elsif child.name == 'ENDNOTE'
      pg_tags = child.xpath("PARALIST/P")
      pg_tags.map {|pg_tag| self.from_tag(pg_tag)}.each do |endnote_paragraph|
        paragraph.add_endnote_paragraph(endnote_paragraph)
      end
    elsif child.name == 'FOOTNOTE'
      pg_tags = child.xpath("PARALIST/P")
      pg_tags.map {|pg_tag| self.from_tag(pg_tag)}.each do |footnote_paragraph|
        paragraph.add_footnote_paragraph(footnote_paragraph)
      end
    elsif child.name == 'TABLE'
      table = Table.from_tag(child)
      paragraph.add_element(table)
    elsif child.name == 'RECTANGLE'
      rectangle = Rectangle.from_tag(child)
      paragraph.add_element(rectangle)
    elsif child.name = 'IMAGE'
      image = Image.from_tag(child)
      paragraph.add_element(image)
    end
  end

  return paragraph
end
new(style_id:, shape_id:) click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 54
def initialize(style_id:, shape_id:)
  @style_id = style_id
  @shape_id = shape_id
  @endnote_paragraphs = []
  @footnote_paragraphs = []
  @elements = []
end

Public Instance Methods

add_element(element) click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 62
def add_element(element)
  @elements << element
end
add_endnote_paragraph(new_paragraph) click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 66
def add_endnote_paragraph(new_paragraph)
  @endnote_paragraphs << new_paragraph
end
add_footnote_paragraph(new_paragraph) click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 70
def add_footnote_paragraph(new_paragraph)
  @footnote_paragraphs << new_paragraph
end
content() click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 74
def content
  return @elements.select{|element| element.textable?}.map {|element| element.content}.join
end
textable?() click to toggle source
# File lib/pnote_client/documents/hml/paragraph.rb, line 78
def textable?
  return true
end