Class: RSpec::Support::EncodedString

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/support/encoded_string.rb

Constant Summary collapse

MRI_UNICODE_UNKOWN_CHARACTER =
"\xEF\xBF\xBD"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, encoding = nil) ⇒ EncodedString

Returns a new instance of EncodedString.



7
8
9
10
11
# File 'lib/rspec/support/encoded_string.rb', line 7

def initialize(string, encoding=nil)
  @encoding = encoding
  @source_encoding = detect_source_encoding(string)
  @string = matching_encoding(string)
end

Instance Attribute Details

#source_encodingObject (readonly)

Returns the value of attribute source_encoding.



12
13
14
# File 'lib/rspec/support/encoded_string.rb', line 12

def source_encoding
  @source_encoding
end

Instance Method Details

#<<(string) ⇒ Object



19
20
21
# File 'lib/rspec/support/encoded_string.rb', line 19

def <<(string)
  @string << matching_encoding(string)
end

#split(regex_or_string) ⇒ Object



23
24
25
# File 'lib/rspec/support/encoded_string.rb', line 23

def split(regex_or_string)
  @string.split(matching_encoding(regex_or_string))
end

#to_sObject Also known as: to_str



27
28
29
# File 'lib/rspec/support/encoded_string.rb', line 27

def to_s
  @string
end