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.



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

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.



11
12
13
# File 'lib/eim_xml.rb', line 11

def encoded_string
  @encoded_string
end

#srcObject (readonly)

Returns the value of attribute src.



11
12
13
# File 'lib/eim_xml.rb', line 11

def src
  @src
end

Class Method Details

.[](obj) ⇒ Object



31
32
33
# File 'lib/eim_xml.rb', line 31

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

.encode(s) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eim_xml.rb', line 14

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



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

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

#write_to(out = "") ⇒ Object



44
45
46
# File 'lib/eim_xml.rb', line 44

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