Class: XML::Feed::Builder::Rss::Item
- Inherits:
-
Object
- Object
- XML::Feed::Builder::Rss::Item
- Defined in:
- lib/xml/libxml/feed/builders/rss.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(channel, node = nil) ⇒ Item
constructor
A new instance of Item.
-
#method_missing(method, *args) ⇒ Object
basic parameters that just get enclosed by a <tag>.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
basic parameters that just get enclosed by a <tag>. More involved stuff should create it’s own pair of methods.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/xml/libxml/feed/builders/rss.rb', line 84 def method_missing(method, *args) meth = method.to_s if meth =~ /=$/ # assignment my_meth = meth.sub(/=$/, '') node = XML::Node.new(my_meth) node.content = args[0].to_s @node << node return node end # if we're reading, we want to collect each node that matches our method name. # the problem is, XML::XPath::Object#find doesn't work on detached nodes, which ours # is at this state. So we have to search manually. array = [] @node.each do |x| if x.name == meth array.push x end end return array.length > 1 ? array : array[0] end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
71 72 73 |
# File 'lib/xml/libxml/feed/builders/rss.rb', line 71 def channel @channel end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
72 73 74 |
# File 'lib/xml/libxml/feed/builders/rss.rb', line 72 def node @node end |