Class: Multibases::EncodedByteArray

Inherits:
ByteArray
  • Object
show all
Defined in:
lib/multibases/byte_array.rb

Instance Method Summary collapse

Methods inherited from ByteArray

#hash, #initialize, #is_a?, #to_arr, #transcode

Constructor Details

This class inherits a constructor from Multibases::ByteArray

Instance Method Details

#chomp!(ord) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/multibases/byte_array.rb', line 57

def chomp!(ord)
  return self unless ord

  __getobj__.reverse!
  index = __getobj__.find_index { |el| el != ord }
  __getobj__.slice!(0, index) unless index.nil?
  __getobj__.reverse!

  self
end

#inspectObject



38
39
40
41
# File 'lib/multibases/byte_array.rb', line 38

def inspect
  encoding = @encoding || Encoding::BINARY
  "[Multibases::EncodedByteArray \"#{to_str(encoding)}\"]"
end

#to_ascii_strObject



49
50
51
# File 'lib/multibases/byte_array.rb', line 49

def to_ascii_str
  to_str(Encoding::US_ASCII)
end

#to_str(encoding = @encoding) ⇒ Object Also known as: to_s

Raises:



43
44
45
46
47
# File 'lib/multibases/byte_array.rb', line 43

def to_str(encoding = @encoding)
  raise MissingEncoding unless encoding

  pack('C*').force_encoding(encoding)
end

#to_utf8_strObject



53
54
55
# File 'lib/multibases/byte_array.rb', line 53

def to_utf8_str
  to_str(Encoding::UTF_8)
end