Class: AcDc::Element
- Inherits:
-
Object
- Object
- AcDc::Element
- Defined in:
- lib/acdc/element.rb
Overview
Basic XML Element
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#options ⇒ Object
Returns the value of attribute options.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#acdc ⇒ Object
Converts the object to XML.
-
#eql?(other) ⇒ Boolean
Overridden to compare the values and not the whole object.
-
#has_many? ⇒ Boolean
True if object has a collection of values.
-
#initialize(value, options = {}, tag = nil) ⇒ Element
constructor
Constructor with the following:.
-
#tag_name ⇒ Object
The name to use for the tag.
Constructor Details
#initialize(value, options = {}, tag = nil) ⇒ Element
Constructor with the following:
12 13 14 15 16 17 |
# File 'lib/acdc/element.rb', line 12 def initialize(value, ={}, tag=nil) @tag = tag ||= self.class.to_s.split("::").last @value = value @options = @attributes = .delete(:attributes) end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/acdc/element.rb', line 6 def attributes @attributes end |
#options ⇒ Object
Returns the value of attribute options.
6 7 8 |
# File 'lib/acdc/element.rb', line 6 def @options end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/acdc/element.rb', line 6 def tag @tag end |
#value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/acdc/element.rb', line 6 def value @value end |
Instance Method Details
#acdc ⇒ Object
Converts the object to XML
20 21 22 23 24 25 26 27 28 |
# File 'lib/acdc/element.rb', line 20 def acdc xml = Builder::XmlMarkup.new if value.nil? xml.tag!(tag_content) else has_many? ? render_many(xml) : xml.tag!(tag_content) {|elem| elem << content} end xml.target! end |
#eql?(other) ⇒ Boolean
Overridden to compare the values and not the whole object
41 42 43 44 45 |
# File 'lib/acdc/element.rb', line 41 def eql?(other) return false if other.nil? return false unless other.kind_of?(self.class) value.eql?(other.value) end |
#has_many? ⇒ Boolean
True if object has a collection of values
31 32 33 |
# File 'lib/acdc/element.rb', line 31 def has_many? .has_key?(:single) and ![:single] and value.size > 1 end |
#tag_name ⇒ Object
The name to use for the tag
36 37 38 |
# File 'lib/acdc/element.rb', line 36 def tag_name tag.to_s.camelize end |