Class: Encoding
Defined Under Namespace
Classes: CompatibilityError, EncodingError
Instance Attribute Summary collapse
-
#default_external ⇒ Object
Returns the value of attribute default_external.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Class Method Summary collapse
Instance Method Summary collapse
- #ascii_compatible? ⇒ Boolean
- #bytesize ⇒ Object
- #dummy? ⇒ Boolean
-
#each_byte ⇒ Object
methods to implement per encoding.
-
#initialize(name, names, ascii, dummy) ⇒ Encoding
constructor
A new instance of Encoding.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, names, ascii, dummy) ⇒ Encoding
Returns a new instance of Encoding.
31 32 33 34 35 36 |
# File 'opal/opal/corelib/string/encoding.rb', line 31 def initialize(name, names, ascii, dummy) @name = name @names = names @ascii = ascii @dummy = dummy end |
Instance Attribute Details
#default_external ⇒ Object
Returns the value of attribute default_external.
27 28 29 |
# File 'opal/opal/corelib/string/encoding.rb', line 27 def default_external @default_external end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'opal/opal/corelib/string/encoding.rb', line 29 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
29 30 31 |
# File 'opal/opal/corelib/string/encoding.rb', line 29 def names @names end |
Class Method Details
.find(name) ⇒ Object
19 20 21 22 23 24 25 |
# File 'opal/opal/corelib/string/encoding.rb', line 19 def self.find(name) return default_external if name == :default_external register = `Opal.encodings` encoding = register.JS[name] || register.JS[name.upcase] raise ArgumentError, "unknown encoding name - #{name}" unless encoding encoding end |
.register(name, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'opal/opal/corelib/string/encoding.rb', line 4 def self.register(name, = {}, &block) names = [name] + ([:aliases] || []) ascii = [:ascii] || false dummy = [:dummy] || false encoding = new(name, names, ascii, dummy) encoding.instance_eval(&block) register = `Opal.encodings` names.each do |encoding_name| const_set encoding_name.sub('-', '_'), encoding register.JS[encoding_name] = encoding end end |
Instance Method Details
#ascii_compatible? ⇒ Boolean
38 39 40 |
# File 'opal/opal/corelib/string/encoding.rb', line 38 def ascii_compatible? @ascii end |
#bytesize ⇒ Object
59 60 61 |
# File 'opal/opal/corelib/string/encoding.rb', line 59 def bytesize(*) raise NotImplementedError end |
#dummy? ⇒ Boolean
42 43 44 |
# File 'opal/opal/corelib/string/encoding.rb', line 42 def dummy? @dummy end |
#each_byte ⇒ Object
methods to implement per encoding
55 56 57 |
# File 'opal/opal/corelib/string/encoding.rb', line 55 def each_byte(*) raise NotImplementedError end |
#inspect ⇒ Object
50 51 52 |
# File 'opal/opal/corelib/string/encoding.rb', line 50 def inspect "#<Encoding:#{@name}#{' (dummy)' if @dummy}>" end |