Class: Encoding

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

Defined Under Namespace

Classes: CompatibilityError, EncodingError

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


36
37
38
39
40
41
# File 'opal/opal/corelib/string/encoding.rb', line 36

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


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

def default_external
  @default_external
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


34
35
36
# File 'opal/opal/corelib/string/encoding.rb', line 34

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names


34
35
36
# File 'opal/opal/corelib/string/encoding.rb', line 34

def names
  @names
end

Class Method Details

.find(name) ⇒ Object

Raises:


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'opal/opal/corelib/string/encoding.rb', line 14

def self.find(name)
  upcase = name.upcase

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

    next unless Encoding === encoding

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

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

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


4
5
6
7
8
9
10
11
12
# File 'opal/opal/corelib/string/encoding.rb', line 4

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:


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

def ascii_compatible?
  @ascii
end

#bytesizeObject


68
69
70
# File 'opal/opal/corelib/string/encoding.rb', line 68

def bytesize(*)
  raise NotImplementedError
end

#dummy?Boolean

Returns:


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

def dummy?
  @dummy
end

#each_byteObject

methods to implement per encoding


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

def each_byte(*)
  raise NotImplementedError
end

#getbyteObject


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

def getbyte(*)
  raise NotImplementedError
end

#inspectObject


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

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

#to_sObject


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

def to_s
  @name
end