Class: XML::Feed::Builder::Rss::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/libxml/feed/builders/rss.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel, node = nil) ⇒ Item

Returns a new instance of Item.



74
75
76
77
78
79
80
# File 'lib/xml/libxml/feed/builders/rss.rb', line 74

def initialize(channel, node=nil)
    @channel = channel
    @node    = node

    @node = XML::Node.new('item') unless @node
    @params = Hash.new
end

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

#channelObject (readonly)

Returns the value of attribute channel.



71
72
73
# File 'lib/xml/libxml/feed/builders/rss.rb', line 71

def channel
  @channel
end

#nodeObject (readonly)

Returns the value of attribute node.



72
73
74
# File 'lib/xml/libxml/feed/builders/rss.rb', line 72

def node
  @node
end