Class: Moxml::Adapter::CustomizedOx::Attribute
- Inherits:
-
Ox::Node
- Object
- Ox::Node
- Moxml::Adapter::CustomizedOx::Attribute
- Defined in:
- lib/moxml/adapter/customized_ox/attribute.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
- #expanded_name ⇒ Object
-
#initialize(attr_name, value, parent = nil) ⇒ Attribute
constructor
A new instance of Attribute.
-
#to_s ⇒ Object
Support string conversion.
-
#to_xml ⇒ Object
Serialize the attribute to XML format with proper escaping.
-
#value ⇒ Object
Expose the value stored in Ox::Node Ox stores attribute values using @value instance variable.
Constructor Details
#initialize(attr_name, value, parent = nil) ⇒ Attribute
Returns a new instance of Attribute.
9 10 11 12 13 14 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 9 def initialize(attr_name, value, parent = nil) self.name = attr_name @parent = parent @value = value # Explicitly set @value super(value) end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 7 def name @name end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 7 def prefix @prefix end |
Instance Method Details
#expanded_name ⇒ Object
25 26 27 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 25 def [prefix, name].compact.join(":") end |
#to_s ⇒ Object
Support string conversion
48 49 50 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 48 def to_s to_xml end |
#to_xml ⇒ Object
Serialize the attribute to XML format with proper escaping
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 36 def to_xml escaped_value = @value.to_s .gsub("&", "&") .gsub("<", "<") .gsub(">", ">") .gsub('"', """) .gsub("'", "'") "#{expanded_name}=\"#{escaped_value}\"" end |
#value ⇒ Object
Expose the value stored in Ox::Node Ox stores attribute values using @value instance variable
31 32 33 |
# File 'lib/moxml/adapter/customized_ox/attribute.rb', line 31 def value @value end |