Class: Encoding
Defined Under Namespace
Classes: CompatibilityError , EncodingError
Class Attribute Summary collapse
-
.default_external ⇒ Object
Returns the value of attribute default_external.
Instance Attribute Summary collapse
-
#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.
- #getbyte ⇒ Object
-
#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.
32 33 34 35 36 37
# File 'opal/opal/corelib/string/encoding.rb', line 32 def initialize(name, names, ascii, dummy) @name = name @names = names @ascii = ascii @dummy = dummy end
Class 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
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32
# File 'opal/opal/corelib/string/encoding.rb', line 30 def name @name end
#names ⇒ Object (readonly)
Returns the value of attribute names.
30 31 32
# File 'opal/opal/corelib/string/encoding.rb', line 30 def names @names end
Class Method Details
.find(name) ⇒ Object
Raises:
18 19 20 21 22 23 24
# File 'opal/opal/corelib/string/encoding.rb', line 18 def self.find(name) return default_external if name == :default_external register = self.JS ['$$register'] encoding = register.JS["$$#{name}"] || register.JS["$$#{name.upcase}"] raise ArgumentError , "unknown encoding name - #{name}" unless encoding encoding end
.register(name, options = {}, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16
# File 'opal/opal/corelib/string/encoding.rb', line 6 def self.register(name, options = {}, &block) names = [name] + (options[:aliases] || []) encoding = Class .new (self, &block) .new(name, names, options[:ascii] || false, options[:dummy] || false) register = self.JS ['$$register'] names.each do |encoding_name| const_set encoding_name.sub('-', '_'), encoding register.JS["$$#{encoding_name}"] = encoding end end
Instance Method Details
#ascii_compatible? ⇒ Boolean
Returns:
- (Boolean )
39 40 41
# File 'opal/opal/corelib/string/encoding.rb', line 39 def ascii_compatible? @ascii end
#bytesize ⇒ Object
Raises:
64 65 66
# File 'opal/opal/corelib/string/encoding.rb', line 64 def bytesize(*) raise NotImplementedError end
#dummy? ⇒ Boolean
Returns:
- (Boolean )
43 44 45
# File 'opal/opal/corelib/string/encoding.rb', line 43 def dummy? @dummy end
#each_byte ⇒ Object
methods to implement per encoding
Raises:
56 57 58
# File 'opal/opal/corelib/string/encoding.rb', line 56 def each_byte(*) raise NotImplementedError end
#getbyte ⇒ Object
Raises:
60 61 62
# File 'opal/opal/corelib/string/encoding.rb', line 60 def getbyte(*) raise NotImplementedError end
#inspect ⇒ Object
51 52 53
# File 'opal/opal/corelib/string/encoding.rb', line 51 def inspect "#<Encoding:#{@name}#{' (dummy)' if @dummy}>" end