lib/rubyfocus/items/ranked_item.rb in rubyfocus-0.3.1 vs lib/rubyfocus/items/ranked_item.rb in rubyfocus-0.4.0

- old
+ new

@@ -1,7 +1,26 @@ class Rubyfocus::RankedItem < Rubyfocus::NamedItem attr_accessor :rank + # Ranked items also happen to be contained items + idref :container + + # Retrieve a full list of the parents of this item. [0] = immediate parent + def ancestry + if container + [container] + container.ancestry + else + [] + end + end + + # Is this item contained within another? You may supply an object, string or integer ID, hash of properties, + # or proc to run on each item. + def contained_within?(object) + object = document.find(object) if [String, Fixnum, Hash, Proc].include?(object.class) + ancestry.include?(object) + end + def apply_xml(n) super(n) conditional_set(:rank, n.at_xpath("xmlns:rank")){ |e| e.inner_html.to_i } end \ No newline at end of file