Class: PnoteClient::Documents::Hml::Paragraph
- Inherits:
-
Object
- Object
- PnoteClient::Documents::Hml::Paragraph
- Defined in:
- lib/pnote_client/documents/hml/paragraph.rb
Instance Attribute Summary collapse
-
#endnote_paragraphs ⇒ Object
readonly
Returns the value of attribute endnote_paragraphs.
-
#footnote_paragraphs ⇒ Object
readonly
Returns the value of attribute footnote_paragraphs.
-
#shape_id ⇒ Object
readonly
Returns the value of attribute shape_id.
-
#style_id ⇒ Object
readonly
Returns the value of attribute style_id.
Class Method Summary collapse
-
.from_tag(pg_tag) ⇒ Object
Textable Element.
Instance Method Summary collapse
- #add_element(element) ⇒ Object
- #add_endnote_paragraph(new_paragraph) ⇒ Object
- #add_footnote_paragraph(new_paragraph) ⇒ Object
- #content ⇒ Object
-
#initialize(style_id:, shape_id:) ⇒ Paragraph
constructor
A new instance of Paragraph.
- #textable? ⇒ Boolean
Constructor Details
#initialize(style_id:, shape_id:) ⇒ Paragraph
Returns a new instance of Paragraph.
54 55 56 57 58 59 60 |
# 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 |
Instance Attribute Details
#endnote_paragraphs ⇒ Object (readonly)
Returns the value of attribute endnote_paragraphs.
52 53 54 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 52 def endnote_paragraphs @endnote_paragraphs end |
#footnote_paragraphs ⇒ Object (readonly)
Returns the value of attribute footnote_paragraphs.
52 53 54 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 52 def footnote_paragraphs @footnote_paragraphs end |
#shape_id ⇒ Object (readonly)
Returns the value of attribute shape_id.
51 52 53 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 51 def shape_id @shape_id end |
#style_id ⇒ Object (readonly)
Returns the value of attribute style_id.
51 52 53 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 51 def style_id @style_id end |
Class Method Details
.from_tag(pg_tag) ⇒ Object
Textable Element
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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' = child.xpath("PARALIST/P") .map {|pg_tag| self.from_tag(pg_tag)}.each do |endnote_paragraph| paragraph.add_endnote_paragraph(endnote_paragraph) end elsif child.name == 'FOOTNOTE' = child.xpath("PARALIST/P") .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 |
Instance Method Details
#add_element(element) ⇒ Object
62 63 64 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 62 def add_element(element) @elements << element end |
#add_endnote_paragraph(new_paragraph) ⇒ Object
66 67 68 |
# 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) ⇒ Object
70 71 72 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 70 def add_footnote_paragraph(new_paragraph) @footnote_paragraphs << new_paragraph end |
#content ⇒ Object
74 75 76 |
# 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? ⇒ Boolean
78 79 80 |
# File 'lib/pnote_client/documents/hml/paragraph.rb', line 78 def textable? return true end |