Module: FFI::Chm::ChmFile::Aux

Includes:
FFI::Chm
Included in:
FFI::Chm::ChmFile
Defined in:
lib/ffi-chm/chm_file/aux.rb

Constant Summary

Constants included from FFI::Chm

VERSION

Constants included from FFI::Chm::Const

FFI::Chm::Const::COMPRESSED, FFI::Chm::Const::ENUMERATE_ALL, FFI::Chm::Const::ENUMERATE_DIRS, FFI::Chm::Const::ENUMERATE_FILES, FFI::Chm::Const::ENUMERATE_FLAGS, FFI::Chm::Const::ENUMERATE_META, FFI::Chm::Const::ENUMERATE_NORMAL, FFI::Chm::Const::ENUMERATE_SPECIAL, FFI::Chm::Const::ENUMERATOR_CONTINUE, FFI::Chm::Const::ENUMERATOR_FAILURE, FFI::Chm::Const::ENUMERATOR_SUCCESS, FFI::Chm::Const::MAX_PATHLEN, FFI::Chm::Const::PARAM_MAX_BLOCKS_CACHED, FFI::Chm::Const::RESOLVE_FAILURE, FFI::Chm::Const::RESOLVE_SUCCESS, FFI::Chm::Const::UNCOMPRESSED

Instance Method Summary collapse

Instance Method Details

#contents(cache = true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/ffi-chm/chm_file/aux.rb', line 27

def contents(cache=true)
  return @contents if @contents
  xml = retrieve_object("/#{self.system.record(6).data.compiled_file}.hhc").com8ble.force_encoding(encoding).encode("UTF-8")
  doc = Struct::HHXDocument.new(Struct::HHC::Entry)
  Nokogiri::HTML::SAX::Parser.new(doc).parse(xml)

  doc.root.first.tap do |v|
    @contents = v if cache
  end
end

#encodingObject



19
20
21
# File 'lib/ffi-chm/chm_file/aux.rb', line 19

def encoding
  @encoding ||= self.system.encoding
end

#fulltext_indexObject

/$FIftiMain



49
50
51
# File 'lib/ffi-chm/chm_file/aux.rb', line 49

def fulltext_index
  @fulltext_index ||= Struct::FulltextIndex.new.read retrieve_object("/$FIftiMain")
end

#fulltext_search(pattern, options = {}, &block) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ffi-chm/chm_file/aux.rb', line 79

def fulltext_search(pattern, options={}, &block)
  pattern = pattern.com8ble.force_encoding('UTF-8').encode(self.encoding).force_encoding("ASCII-8BIT")
  context =
    case options[:context]
    when :title
      0
    when :body
      1
    end

  case fulltext_index.depth.to_i
  when 1
    search_inner_prefix fulltext_index.root.to_a, pattern, context, &block
  when 2
    search_inner_prefix fulltext_index.root.records, pattern, context, &block
  else
    raise "Index tree is too deep(#{fulltext_index.depth})."
  end
end

#index(cache = true) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ffi-chm/chm_file/aux.rb', line 38

def index(cache=true)
  return @index if @index
  xml = retrieve_object("/#{self.system.record(6).data.compiled_file}.hhk").com8ble.force_encoding(encoding).encode("UTF-8")
  doc = Struct::HHXDocument.new(Struct::HHK::Entry)
  Nokogiri::HTML::SAX::Parser.new(doc).parse(xml)
  doc.root.flatten.tap do |v|
    @index = v if cache
  end
end

#string(offset) ⇒ Object

/#STRINGS



54
55
56
57
58
59
60
61
62
63
# File 'lib/ffi-chm/chm_file/aux.rb', line 54

def string(offset)
  @string ||= {}
  if @string.has_key? offset
    @string[offset]
  else
    io = StringIO.new raw_strings
    io.seek offset
    @string[offset] = BinData::Stringz.new.read(io).to_s.com8ble.force_encoding(encoding).encode("UTF-8")
  end
end

#systemObject

/#SYSTEM



8
9
10
# File 'lib/ffi-chm/chm_file/aux.rb', line 8

def system
  @system ||= Struct::System.new.read retrieve_object("/#SYSTEM")
end

#titleObject



23
24
25
# File 'lib/ffi-chm/chm_file/aux.rb', line 23

def title
  @title ||= self.system.record(3).data.title.com8ble.force_encoding(encoding).encode("UTF-8")
end

#topicsObject

/#TOPICS



13
14
15
16
17
# File 'lib/ffi-chm/chm_file/aux.rb', line 13

def topics
  @topics ||= Struct::Topics.new.read retrieve_object("/#TOPICS")
  @topics.set_context self
  @topics
end

#url_string(offset) ⇒ Object

/#URLSTR



73
74
75
76
77
# File 'lib/ffi-chm/chm_file/aux.rb', line 73

def url_string(offset)
  io = StringIO.new raw_urlstr
  io.seek offset
  FFI::Chm::Struct::URLString.new.read io
end

#url_table(offset) ⇒ Object

/#URLTBL



66
67
68
69
70
# File 'lib/ffi-chm/chm_file/aux.rb', line 66

def url_table(offset)
  io = StringIO.new raw_urltbl
  io.seek offset
  Struct::URLTable::URLTableRecord.new.read(io)
end