Class: FFI::Chm::ChmFile

Inherits:
Object
  • Object
show all
Includes:
Aux
Defined in:
lib/ffi-chm/chm_file.rb

Defined Under Namespace

Modules: Aux

Constant Summary

Constants included from FFI::Chm

VERSION

Constants included from 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 Attribute Summary collapse

Instance Method Summary collapse

Methods included from Aux

#contents, #encoding, #fulltext_index, #fulltext_search, #index, #string, #system, #title, #topics, #url_string, #url_table

Constructor Details

#initialize(path, &block) ⇒ ChmFile

Returns a new instance of ChmFile.



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

def initialize(path, &block)
  @path = path
  self.open &block if block_given?
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#closeObject



28
29
30
# File 'lib/ffi-chm/chm_file.rb', line 28

def close
  API.chm_close @h unless @h.null?
end

#enumerate(*what, &block) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/ffi-chm/chm_file.rb', line 59

def enumerate(*what, &block)
  if block_given?
    API.chm_enumerate @h, to_flags(what), enum_func(&block), nil
    self
  else
    Com8ble::Enumerator.new self, :enumerate, to_flags(what)
  end
end

#enumerate_dir(prefix, *what, &block) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/ffi-chm/chm_file.rb', line 68

def enumerate_dir(prefix, *what, &block)
  if block_given?
    API.chm_enumerate_dir @h, prefix, to_flags(what), enum_func(&block), nil
    self
  else
    Com8ble::Enumerator.new self, :enumerate_dir, prefix, to_flags(what)
  end
end

#open(path = @path, &block) ⇒ Object

Raises:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ffi-chm/chm_file.rb', line 13

def open(path=@path, &block)
  @path = path
  @h = API.chm_open @path
  raise ChmError, "Not exists?" if @h.null?
  if block_given?
    begin
      yield self
    ensure
      self.close
    end
  else
    self
  end
end

#resolve_object(name) ⇒ Object



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

def resolve_object(name)
  ui = UnitInfo.new
  case API.chm_resolve_object @h, name, ui
  when Const::RESOLVE_SUCCESS
    ui
  when Const::RESOLVE_FAILURE
    raise ResolveError
  end
end

#retrieve_object(ui) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ffi-chm/chm_file.rb', line 46

def retrieve_object(ui)
  if UnitInfo === ui
    buf = FFI::Buffer.new ui[:length]
    API.chm_retrieve_object @h, ui, buf, 0, ui[:length]
    # use read_string for JRuby
    buf.read_bytes buf.size
  else
    retrieve_object resolve_object(ui)
  end
rescue ResolveError
  raise RetrieveError, ui
end

#set_param(param, value) ⇒ Object



32
33
34
# File 'lib/ffi-chm/chm_file.rb', line 32

def set_param(param, value)
  API.chm_set_param @h, param, value
end