Class: EimXML::PCString

Inherits:
Object
  • Object
show all
Defined in:
lib/eim_xml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, encoded = false) ⇒ PCString

Returns a new instance of PCString.



41
42
43
44
# File 'lib/eim_xml.rb', line 41

def initialize(s, encoded=false)
	@src = s
	@encoded_string = encoded ? s : PCString.encode(s)
end

Instance Attribute Details

#encoded_stringObject (readonly) Also known as: to_s

Returns the value of attribute encoded_string.



17
18
19
# File 'lib/eim_xml.rb', line 17

def encoded_string
  @encoded_string
end

#srcObject (readonly)

Returns the value of attribute src.



17
18
19
# File 'lib/eim_xml.rb', line 17

def src
  @src
end

Class Method Details

.[](obj) ⇒ Object



37
38
39
# File 'lib/eim_xml.rb', line 37

def self.[](obj)
	obj.is_a?(PCString) ? obj : PCString.new(obj)
end

.encode(s) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eim_xml.rb', line 20

def self.encode(s)
	s.to_s.gsub(/[&\"\'<>]/) do |m|
		case m
		when "&"
			"&amp;"
		when '"'
			"&quot;"
		when "'"
			"&apos;"
		when "<"
			"&lt;"
		when ">"
			"&gt;"
		end
	end
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
# File 'lib/eim_xml.rb', line 46

def ==(other)
	other.is_a?(PCString) ? @encoded_string==other.encoded_string : self==PCString.new(other)
end

#write_to(out = "") ⇒ Object



50
51
52
# File 'lib/eim_xml.rb', line 50

def write_to(out="")
	out << encoded_string
end