Class: PnoteClient::Documents::Hml

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_itemsObject (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

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



11
12
13
# File 'lib/pnote_client/documents/hml.rb', line 11

def paragraphs
  @paragraphs
end

#stylesObject (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.message)
  end

  # 빈 TEXT 삭제
  doc.xpath("//P[TEXT[not(node())]]").each do |p|
    p.remove
  end

  style_tags = doc.xpath("//STYLELIST/STYLE")
  style_tags.each do |style_tag|
    styles << Style.from_tag(style_tag)
  end

  pg_tags = doc.xpath("//SECTION/P")
  pg_tags.each do |pg_tag|
    paragraphs << Paragraph.from_tag(pg_tag)
  end

  bin_item_tags = doc.xpath("//BINITEM")
  bin_item_tags.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