Class: AcDc::Item
Constant Summary collapse
- Types =
[String, Float, Time, Date, DateTime, Integer, Boolean]
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.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #attribute? ⇒ Boolean
- #constant ⇒ Object
- #element? ⇒ Boolean
-
#initialize(name, type, options = {}) ⇒ Item
constructor
A new instance of Item.
- #method_name ⇒ Object
- #primitive? ⇒ Boolean
- #renderable? ⇒ Boolean
- #single? ⇒ Boolean
- #value_from_xml(node, namespace) ⇒ Object
- #xpath(namespace = self.namespace) ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ Item
Returns a new instance of Item.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/acdc/item.rb', line 7 def initialize(name, type, ={}) @name = name.to_s @type = type @renderable = .delete(:render_empty) @renderable = true if @renderable.nil? @tag = .delete(:tag) || @type.tag_name rescue nil || name.to_s @options = @xml_type = self.class.to_s.split('::').last.downcase end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/acdc/item.rb', line 5 def name @name end |
#namespace ⇒ Object
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/acdc/item.rb', line 5 def namespace @namespace end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/acdc/item.rb', line 5 def @options end |
#tag ⇒ Object
Returns the value of attribute tag.
5 6 7 |
# File 'lib/acdc/item.rb', line 5 def tag @tag end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/acdc/item.rb', line 5 def type @type end |
Instance Method Details
#constant ⇒ Object
27 28 29 |
# File 'lib/acdc/item.rb', line 27 def constant @constant ||= constantize(type) end |
#element? ⇒ Boolean
35 36 37 |
# File 'lib/acdc/item.rb', line 35 def element? @xml_type == 'element' end |
#method_name ⇒ Object
23 24 25 |
# File 'lib/acdc/item.rb', line 23 def method_name @method_name ||= name.tr('-','_') end |
#primitive? ⇒ Boolean
53 54 55 |
# File 'lib/acdc/item.rb', line 53 def primitive? Types.include?(constant) end |
#single? ⇒ Boolean
31 32 33 |
# File 'lib/acdc/item.rb', line 31 def single? @single ||= [:single].nil? || [:single] end |
#value_from_xml(node, namespace) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/acdc/item.rb', line 43 def value_from_xml(node, namespace) n = find(node,namespace) if primitive? value = n.respond_to?(:content) ? n.content : n.to_s typecast(value) else constant.acdc(n) end end |
#xpath(namespace = self.namespace) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/acdc/item.rb', line 57 def xpath(namespace = self.namespace) xpath = '' xpath += "#{DEFAULT_NAMESPACE}:" if namespace xpath += tag xpath end |