Class: Encoding

Inherits:
Object show all
Defined in:
opal/stdlib/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



35
36
37
38
39
40
# File 'opal/stdlib/encoding.rb', line 35

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



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

def default_external
  @default_external
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



33
34
35
# File 'opal/stdlib/encoding.rb', line 33

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names



33
34
35
# File 'opal/stdlib/encoding.rb', line 33

def names
  @names
end

Class Method Details

.find(name) ⇒ Object

Raises:

  • (ArgumentError)


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

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

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

    if encoding.name == upcase_name || encoding.names.include?(upcase_name)
      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/stdlib/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:



42
43
44
# File 'opal/stdlib/encoding.rb', line 42

def ascii_compatible?
  @ascii
end

#bytesizeObject

Raises:

  • (NotImplementedError)


67
68
69
# File 'opal/stdlib/encoding.rb', line 67

def bytesize(*)
  raise NotImplementedError
end

#dummy?Boolean

Returns:



46
47
48
# File 'opal/stdlib/encoding.rb', line 46

def dummy?
  @dummy
end

#each_byteObject

methods to implement per encoding

Raises:

  • (NotImplementedError)


59
60
61
# File 'opal/stdlib/encoding.rb', line 59

def each_byte(*)
  raise NotImplementedError
end

#getbyteObject

Raises:

  • (NotImplementedError)


63
64
65
# File 'opal/stdlib/encoding.rb', line 63

def getbyte(*)
  raise NotImplementedError
end

#inspectObject



54
55
56
# File 'opal/stdlib/encoding.rb', line 54

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

#to_sObject



50
51
52
# File 'opal/stdlib/encoding.rb', line 50

def to_s
  @name
end