Module: COM

Defined in:
lib/com.rb,
lib/com/version.rb

Overview

COM is an object-oriented wrapper around WIN32OLE. COM makes it easy to add behavior to WIN32OLE objects, making them easier to work with from Ruby.

Defined Under Namespace

Modules: HResultError, PatternError, StandardError Classes: Error, Events, Instantiable, MethodInvocationError, Object, Wrapper

Constant Summary collapse

Version =
'0.3.1'

Class Method Summary collapse

Class Method Details

.charsetString

Gets the iconv character set equivalent of the current COM code page.

Returns:

  • (String)

    The iconv character set

Raises:

  • (RuntimeError)

    If no iconv charset is associated with the current COM codepage



23
24
25
26
27
# File 'lib/com.rb', line 23

def charset
  COMCodePageToIconvCharset[WIN32OLE.codepage] or
    raise 'no iconv charset associated with current COM codepage: %s' %
      WIN32OLE.codepage
end

.connect(id) ⇒ COM::MethodMissing

Connects to a running COM object.

This method shouldn’t be used directly, but rather is used by COM::Object.

Parameters:

  • id (String)

    The program ID of the COM object to connect to

Returns:

  • (COM::MethodMissing)

    The running COM object wrapped in a COM::MethodMissing

Raises:

  • (COM::Error)

    Any error that may have occurred while trying to connect



39
40
41
42
43
# File 'lib/com.rb', line 39

def connect(id)
  Wrapper.new(WIN32OLE.connect(id))
rescue WIN32OLERuntimeError => e
  raise Error.from(e)
end

.new(id, host = nil) ⇒ COM::MethodMissing

Creates a new COM object.

This method shouldn’t be used directly, but rather is used by COM::Object.

Parameters:

  • id (String)

    The program ID of the COM object to create

  • host (String, nil) (defaults to: nil)

    The host of the program ID

Returns:

  • (COM::MethodMissing)

    The COM object wrapped in a COM::MethodMissing

Raises:

  • (COM::Error)

    Any error that may have occurred while trying to create the COM object



55
56
57
58
59
# File 'lib/com.rb', line 55

def new(id, host = nil)
  Wrapper.new(WIN32OLE.new(id, host))
rescue WIN32OLERuntimeError => e
  raise Error.from(e)
end