Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'rspec'
- def split(original)
- original.split("/").inject([]) do |result, element|
- result + [(result.last||[]) + [element]]
- end.reverse.map{ |variation| variation.join("/") }
- end
- describe "#category" do
- it "should split the categories out" do
- split("bc6/energy/fuel/organic").should == ["bc6/energy/fuel/organic", "bc6/energy/fuel", "bc6/energy", "bc6"]
- end
- end
- def category=(cat)
- temp_cat = cat.clone
- self.categories = 3.upto(temp_cat.split("/").length).collect do |variable|
- temp_cat = temp_cat.split("/").tap(&:pop).join("/")
- end.insert(0,cat)
- end
Add Comment
Please, Sign In to add comment