Class: FFI::Chm::Struct::HHXDocument

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/ffi-chm/struct/hhx_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry_klass) ⇒ HHXDocument

Returns a new instance of HHXDocument.



6
7
8
# File 'lib/ffi-chm/struct/hhx_document.rb', line 6

def initialize(entry_klass)
  @klass = entry_klass
end

Instance Attribute Details

#rootObject (readonly)

ul - li - object - param



4
5
6
# File 'lib/ffi-chm/struct/hhx_document.rb', line 4

def root
  @root
end

Instance Method Details

#end_element(name, *attributes) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ffi-chm/struct/hhx_document.rb', line 32

def end_element(name, *attributes)
  case name
  when "object" # li results broken structure.
    @heads.last << @entry if @entry
  when "ul"
    @heads.pop
  end
end

#start_documentObject



10
11
12
13
14
# File 'lib/ffi-chm/struct/hhx_document.rb', line 10

def start_document
  @root = []
  @heads = []
  @heads << @root
end

#start_element(name, attributes = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ffi-chm/struct/hhx_document.rb', line 16

def start_element(name, attributes = [])
  case name
  when "param"
    return unless @entry
    attr = {}
    attributes.each{|k, v| attr[k.intern] = v }
    @entry[attr[:name].intern] = attr[:value]
  when "li"
    @entry = @klass.new
  when "ul"
    head = []
    @heads.last << head
    @heads << head
  end
end