Class: MiniSpec::Differ::EncodedString

Inherits:
Object
  • Object
show all
Defined in:
lib/minispec/utils/differ.rb

Constant Summary collapse

MRI_UNICODE_UNKNOWN_CHARACTER =
"\xEF\xBF\xBD".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, encoding = nil) ⇒ EncodedString

Returns a new instance of EncodedString.



32
33
34
35
36
# File 'lib/minispec/utils/differ.rb', line 32

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.



37
38
39
# File 'lib/minispec/utils/differ.rb', line 37

def source_encoding
  @source_encoding
end

Instance Method Details

#<<(string) ⇒ Object



44
45
46
# File 'lib/minispec/utils/differ.rb', line 44

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

#split(regex_or_string) ⇒ Object



48
49
50
# File 'lib/minispec/utils/differ.rb', line 48

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

#to_sObject Also known as: to_str



52
53
54
# File 'lib/minispec/utils/differ.rb', line 52

def to_s
  @string
end