lib/asynchronic/data_store/key.rb in asynchronic-0.1.0 vs lib/asynchronic/data_store/key.rb in asynchronic-0.2.0
- old
+ new
@@ -1,14 +1,32 @@
module Asynchronic
module DataStore
class Key < String
+ SEPARATOR = '|'
+
def initialize(key)
super key.to_s
end
def [](key)
- self.class.new "#{self}:#{key}"
+ self.class.new [self,key].join(SEPARATOR)
+ end
+
+ def sections
+ split SEPARATOR
+ end
+
+ def nested?
+ sections.count > 1
+ end
+
+ def remove_first(count=1)
+ self.class.new sections[count..-1].join(SEPARATOR)
+ end
+
+ def remove_last(count=1)
+ self.class.new sections[0..-count-1].join(SEPARATOR)
end
end
end
end
\ No newline at end of file