Class: PnoteClient::Documents::Hml
- Inherits:
-
Object
- Object
- PnoteClient::Documents::Hml
- Defined in:
- lib/pnote_client/documents/hml.rb,
lib/pnote_client/documents/hml/char.rb,
lib/pnote_client/documents/hml/image.rb,
lib/pnote_client/documents/hml/style.rb,
lib/pnote_client/documents/hml/table.rb,
lib/pnote_client/documents/hml/equation.rb,
lib/pnote_client/documents/hml/paragraph.rb,
lib/pnote_client/documents/hml/rectangle.rb,
lib/pnote_client/documents/hml/table_row.rb,
lib/pnote_client/documents/hml/table_cell.rb,
lib/pnote_client/documents/hml/paragraph_reader.rb,
lib/pnote_client/documents/hml/embedding_binary_item.rb
Defined Under Namespace
Classes: Char, EmbeddingBinaryItem, Equation, Image, Paragraph, ParagraphReader, Rectangle, Style, Table, TableCell, TableRow
Instance Attribute Summary collapse
-
#bin_items ⇒ Object
readonly
Returns the value of attribute bin_items.
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(styles: [], paragraphs: [], bin_items: []) ⇒ Hml
constructor
A new instance of Hml.
Constructor Details
#initialize(styles: [], paragraphs: [], bin_items: []) ⇒ Hml
Returns a new instance of Hml.
48 49 50 51 52 |
# File 'lib/pnote_client/documents/hml.rb', line 48 def initialize(styles: [], paragraphs: [], bin_items: []) @styles = styles @paragraphs = paragraphs @bin_items = bin_items end |
Instance Attribute Details
#bin_items ⇒ Object (readonly)
Returns the value of attribute bin_items.
11 12 13 |
# File 'lib/pnote_client/documents/hml.rb', line 11 def bin_items @bin_items end |
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
11 12 13 |
# File 'lib/pnote_client/documents/hml.rb', line 11 def paragraphs @paragraphs end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
11 12 13 |
# File 'lib/pnote_client/documents/hml.rb', line 11 def styles @styles end |
Class Method Details
.parse(hml_content) ⇒ Object
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 |
# File 'lib/pnote_client/documents/hml.rb', line 13 def self.parse(hml_content) styles = [] paragraphs = [] bin_items = [] doc = Nokogiri::XML(hml_content) unless doc.errors.empty? raise InvalidXMLError.new(doc.errors.first.) end # 빈 TEXT 삭제 doc.xpath("//P[TEXT[not(node())]]").each do |p| p.remove end = doc.xpath("//STYLELIST/STYLE") .each do |style_tag| styles << Style.from_tag(style_tag) end = doc.xpath("//SECTION/P") .each do |pg_tag| paragraphs << Paragraph.from_tag(pg_tag) end = doc.xpath("//BINITEM") .each_with_index do |bin_item_tag, index| bin_item_id = index + 1 if bin_item_tag['Type'] == 'Embedding' bin_items << EmbeddingBinaryItem.new(bin_item_id, bin_item_tag, doc) end end return self.new(styles: styles, paragraphs: paragraphs, bin_items: bin_items) end |