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

COMCodePageToIconvCharset =
{
  WIN32OLE::CP_UTF8 => 'UTF-8'
}.freeze
Version =
'0.4.0'

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



15
16
17
18
19
# File 'lib/com.rb', line 15

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



31
32
33
34
35
# File 'lib/com.rb', line 31

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



47
48
49
50
51
# File 'lib/com.rb', line 47

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