Class: Base4R::Attribute
- Inherits:
-
Object
- Object
- Base4R::Attribute
- Defined in:
- lib/attribute.rb
Overview
Attributes are typed key-value pairs that describe content. Attributes describe the Base Item. Client code should use subclasses of Attribute such as TextAttribute, BareAttribute, DateTimeAttribute, IntAttribute, FloatUnitAttribute, UrlAttribute, LocationAttribute, BooleanAttribute. Each of these can represent themselves as required by the Atom format.
Direct Known Subclasses
AuthorAttribute, BareAttribute, BooleanAttribute, DateTimeAttribute, IntAttribute, LocationAttribute, ReferenceAttribute, SomethingUnits, TextAttribute, UrlAttribute
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#options ⇒ Object
Returns the value of attribute options.
-
#private_attribute ⇒ Object
Returns the value of attribute private_attribute.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.to_xml(parent, name, value, options = {}) ⇒ Object
Create an xml object with this BareAttribute.new(parent, :myattr, ‘love’, :private_attribute => true).
-
.type_name ⇒ Object
keep this pure ruby instead of using rails stuff.
Instance Method Summary collapse
- #private_attribute? ⇒ Boolean
-
#to_xml(parent, options = {}) ⇒ Object
Represent this Attribute as an XML element that is a child of parent.
-
#type_name ⇒ Object
the type name for this attribute.
- #type_name=(value) ⇒ Object
Methods included from AdditionalXmlAttributeMethods
#additional_xml_attribute_map, included, #xml_attribute_value, #xml_attributes
Methods included from ChildAttributeMethods
#add_child, #add_child_attribute, #child, #children, #children_map, #children_names, included
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
134 135 136 |
# File 'lib/attribute.rb', line 134 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
136 137 138 |
# File 'lib/attribute.rb', line 136 def namespace @namespace end |
#options ⇒ Object
Returns the value of attribute options.
137 138 139 |
# File 'lib/attribute.rb', line 137 def @options end |
#private_attribute ⇒ Object
Returns the value of attribute private_attribute.
138 139 140 |
# File 'lib/attribute.rb', line 138 def private_attribute @private_attribute end |
#value ⇒ Object
Returns the value of attribute value.
135 136 137 |
# File 'lib/attribute.rb', line 135 def value @value end |
Class Method Details
.to_xml(parent, name, value, options = {}) ⇒ Object
Create an xml object with this
BareAttribute.new(parent, :myattr, 'love', :private_attribute => true)
182 183 184 |
# File 'lib/attribute.rb', line 182 def to_xml(parent, name, value, ={}) new( name, value, ).to_xml(parent) end |
.type_name ⇒ Object
keep this pure ruby instead of using rails stuff
177 178 179 |
# File 'lib/attribute.rb', line 177 def type_name self.to_s.gsub(/^Base4R::(\w)(\w*)Attribute$/) { "#{$1.downcase}#{$2}" } end |
Instance Method Details
#private_attribute? ⇒ Boolean
168 |
# File 'lib/attribute.rb', line 168 def private_attribute?; private_attribute.is_a?(TrueClass); end |
#to_xml(parent, options = {}) ⇒ Object
Represent this Attribute as an XML element that is a child of parent.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/attribute.rb', line 144 def to_xml(parent, ={}) return if value.nil? && children.empty? && ![:force].is_a?(TrueClass) el = parent.add_element(calc_el_name) el.add_attribute('type', type_name) if type_name && !type_name.empty? el.add_attribute('access', 'private') if private_attribute? #add additional attributes like href=http://meh.com additional_xml_attribute_map.each { |k,v| el.add_attribute(k.to_s, v.to_s) if v } el.text = value.to_s if value children.each {|child| child.to_xml(el) } el end |
#type_name ⇒ Object
the type name for this attribute
173 |
# File 'lib/attribute.rb', line 173 def type_name; @type_name || self.class.type_name; end |
#type_name=(value) ⇒ Object
170 |
# File 'lib/attribute.rb', line 170 def type_name=(value); @type_name=value.to_s; end |