# File lib/structures.rb, line 29
29: def ==(other)
30: other.equal?(self) ||
31: (other.instance_of?(self.class) &&
32: self.class::ELEMENTS.all?{ |el| self.send(el) == other.send(el)} )
33: end
Returns the difference between two Feed instances as a hash. Any top-level differences in the Feed object as presented as:
{ :title => [content, other_content] }
For differences at the items level, an array of hashes shows the diffs on a per-entry basis. Only entries that differ will contain a hash:
{ :items => [
{:title => ["An article tile", "A new article title"]},
{:title => ["one title", "a different title"]} ]}
If the number of items in each feed are different, then the count of each is provided instead:
{ :items => [4,5] }
This method can also be useful for human-readable feed comparison if its output is dumped to YAML.
# File lib/structures.rb, line 54
54: def diff(other, elements = self.class::ELEMENTS)
55: diffs = {}
56:
57: elements.each do |element|
58: if other.respond_to?(element)
59: self_value = self.send(element)
60: other_value = other.send(element)
61:
62: next if self_value == other_value
63:
64: diffs[element] = if other_value.respond_to?(:diff)
65: self_value.diff(other_value)
66:
67: elsif other_value.is_a?(Enumerable) && other_value.all?{|v| v.respond_to?(:diff)}
68:
69: if self_value.size != other_value.size
70: [self_value.size, other_value.size]
71: else
72: enum_diffs = []
73: self_value.each_with_index do |val, index|
74: enum_diffs << val.diff(other_value[index], val.class::ELEMENTS)
75: end
76: enum_diffs.reject{|h| h.empty?}
77: end
78:
79: else
80: [other_value, self_value] unless other_value == self_value
81: end
82: end
83: end
84:
85: diffs
86: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.