Class: CodePages::CodePage

Inherits:
Object
  • Object
show all
Defined in:
lib/code-pages/code_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, resource_file) ⇒ CodePage

Returns a new instance of CodePage.



7
8
9
10
# File 'lib/code-pages/code_page.rb', line 7

def initialize(id, resource_file)
  @id = id
  @resource_file = resource_file
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/code-pages/code_page.rb', line 5

def id
  @id
end

#resource_fileObject (readonly)

Returns the value of attribute resource_file.



5
6
7
# File 'lib/code-pages/code_page.rb', line 5

def resource_file
  @resource_file
end

Instance Method Details

#to_utf8(str) ⇒ Object



12
13
14
# File 'lib/code-pages/code_page.rb', line 12

def to_utf8(str)
  str.each_byte.map { |byte| unicode_mapping[byte] }.pack('U*')
end

#unicode_mappingObject



16
17
18
# File 'lib/code-pages/code_page.rb', line 16

def unicode_mapping
  @unicode_mapping ||= YAML.load_file(resource_file)
end