Class: Encoding

Inherits:
Object
  • Object
show all
Defined in:
opal/opal/corelib/encoding.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, names, ascii, dummy) ⇒ Encoding

Returns a new instance of Encoding



32
33
34
35
36
37
# File 'opal/opal/corelib/encoding.rb', line 32

def initialize(name, names, ascii, dummy)
  @name  = name
  @names = names
  @ascii = ascii
  @dummy = dummy
end

Class Attribute Details

.default_externalObject

Returns the value of attribute default_external



27
28
29
# File 'opal/opal/corelib/encoding.rb', line 27

def default_external
  @default_external
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



30
31
32
# File 'opal/opal/corelib/encoding.rb', line 30

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names



30
31
32
# File 'opal/opal/corelib/encoding.rb', line 30

def names
  @names
end

Class Method Details

.find(name) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'opal/opal/corelib/encoding.rb', line 12

def self.find(name)
  return name if self === name

  constants.each {|const|
    encoding = const_get(const)

    if encoding.name == name || encoding.names.include?(name)
      return encoding
    end
  }

  raise ArgumentError, "unknown encoding name - #{name}"
end

.register(name, options = {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'opal/opal/corelib/encoding.rb', line 2

def self.register(name, options = {}, &block)
  names    = [name] + (options[:aliases] || [])
  encoding = Class.new(self, &block).
    new(name, names, options[:ascii] || false, options[:dummy] || false)

  names.each {|name|
    const_set name.sub('-', '_'), encoding
  }
end

Instance Method Details

#ascii_compatible?Boolean

Returns:



39
40
41
# File 'opal/opal/corelib/encoding.rb', line 39

def ascii_compatible?
  @ascii
end

#bytesizeObject



64
65
66
# File 'opal/opal/corelib/encoding.rb', line 64

def bytesize(*)
  raise NotImplementedError
end

#dummy?Boolean

Returns:



43
44
45
# File 'opal/opal/corelib/encoding.rb', line 43

def dummy?
  @dummy
end

#each_byteObject

methods to implement per encoding



56
57
58
# File 'opal/opal/corelib/encoding.rb', line 56

def each_byte(*)
  raise NotImplementedError
end

#getbyteObject



60
61
62
# File 'opal/opal/corelib/encoding.rb', line 60

def getbyte(*)
  raise NotImplementedError
end

#inspectObject



51
52
53
# File 'opal/opal/corelib/encoding.rb', line 51

def inspect
  "#<Encoding:#{@name}#{" (dummy)" if @dummy}>"
end

#to_sObject



47
48
49
# File 'opal/opal/corelib/encoding.rb', line 47

def to_s
  @name
end