Class: Saxon::ItemType::LexicalStringConversion::ByteConversion
- Inherits:
-
Object
- Object
- Saxon::ItemType::LexicalStringConversion::ByteConversion
- Defined in:
- lib/saxon/item_type/lexical_string_conversion.rb
Overview
Convert Bytes. Idiomatically, Ruby uses ASCII_8BIT
encoded strings to represent bytes, and so a single character represents a single byte. XDM uses the decimal value of a signed or unsigned 8 bit integer
Instance Attribute Summary collapse
-
#unpack_format ⇒ Object
readonly
Returns the value of attribute unpack_format.
Instance Method Summary collapse
- #call(value, item_type) ⇒ Object
-
#initialize(kind = :signed) ⇒ ByteConversion
constructor
A new instance of ByteConversion.
Constructor Details
#initialize(kind = :signed) ⇒ ByteConversion
Returns a new instance of ByteConversion.
211 212 213 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 211 def initialize(kind = :signed) @unpack_format = kind == :unsigned ? 'C' : 'c' end |
Instance Attribute Details
#unpack_format ⇒ Object (readonly)
Returns the value of attribute unpack_format.
209 210 211 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 209 def unpack_format @unpack_format end |
Instance Method Details
#call(value, item_type) ⇒ Object
215 216 217 218 219 |
# File 'lib/saxon/item_type/lexical_string_conversion.rb', line 215 def call(value, item_type) raise Errors::RubyValueOutOfBounds.new(value, item_type) if value.bytesize != 1 value = value.to_s.force_encoding(Encoding::ASCII_8BIT) value.unpack(unpack_format).first.to_s end |