Module: Encoding::CodePage

Included in:
Encoding
Defined in:
lib/encoding-codepage.rb

Overview

Encoding::Codepage adds two methods to the Encoding class to help you look Encodings by their Microsoft® Codae Page Identifier. It doesn’t add support to Ruby for Encodings that are not already supported, just makes it easier to find those encodings which are.

At the moment, this list is available on the web at:

Instance Method Summary collapse

Instance Method Details

#codepage(id) ⇒ Object

Find an Encoding object from a Micrsoft® Code Page Identifier.

A list of Code Page identifiers can be found at:

NOTE: This library doesn’t add support for all Code Pages, it merely allows you to look up existing encodings by their Code Page Identifier.

Parameters:

  • Integer

    The Code Page Identifier.

Returns:

  • Encoding The Encoding object.

Raises:

  • ArgumentError The Code Page you tried to find doesn’t exist.



24
25
26
# File 'lib/encoding-codepage.rb', line 24

def codepage(id)
  Encoding.find("CP#{id}")
end

#codepage?(id) ⇒ Encoding?

Determine whether a Code Page exists with the given Code Page Identifier.

Parameters:

  • Integer

    The Code Page Identifier.

Returns:

  • (Encoding, nil)

    The Encoding iff it exists.



44
45
46
# File 'lib/encoding-codepage.rb', line 44

def codepage?(id)
  exist?("CP#{id}")
end

#exist?(name) ⇒ Encoding?

Determine whether an Encoding exists with the given name.

Parameters:

  • String

    The name to search for.

Returns:

  • (Encoding, nil)

    The Encoding iff it exists.



33
34
35
36
37
# File 'lib/encoding-codepage.rb', line 33

def exist?(name)
  find(name)
rescue ArgumentError => e
  nil
end