added #parent_group method to Label and Key objects

This commit is contained in:
2011-03-09 10:25:37 +00:00
parent 325a264411
commit ac338bb4f0
4 changed files with 20 additions and 0 deletions

View File

@@ -53,6 +53,10 @@ module Redistat
end
end
def parent_group
@label.parent_group
end
def to_s(depth = nil)
depth ||= @options[:depth]
key = self.prefix

View File

@@ -49,5 +49,9 @@ module Redistat
@groups.reverse!
end
def parent_group
groups[-2]
end
end
end

View File

@@ -73,4 +73,10 @@ describe Redistat::Key do
key.groups.map { |k| k.label }.should == result
end
it "should know it's parent label group" do
label = 'message/public/offensive'
key = Redistat::Key.new(@scope, label, @date, {:depth => :hour})
key.parent_group.should == 'message/public'
end
end

View File

@@ -45,4 +45,10 @@ describe Redistat::Label do
label.groups.should == [ "message" ]
end
it "should know it's parent label group" do
name = "message/public/offensive"
label = Redistat::Label.new(name)
label.parent_group.should == 'message/public'
end
end