Skip to content

Commit

Permalink
Add methods to ordered_hash for use is docomo_css
Browse files Browse the repository at this point in the history
  • Loading branch information
pwim committed Dec 20, 2010
1 parent 1b3abea commit 66e47ba
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/tiny_css/ordered_hash.rb
Expand Up @@ -44,5 +44,27 @@ def inspect
each { |k, v| ary << "#{ k.inspect }=>#{ v.inspect }" }
"{#{ ary.join(', ') }}"
end

def to_s
map { |k, v| "#{ k }:#{ v }" }.join ';'
end

def empty?
@hash.empty?
end

def key?(key)
keys.include?(key)
end

def split(*keys_to_split)
h = self.class.new
keys.detect {|k| keys_to_split.include?(k) }.each do |k|
if v = delete(k)
h[k] = v
end
end
h
end
end
end
41 changes: 41 additions & 0 deletions spec/ordered_hash_spec.rb
Expand Up @@ -185,3 +185,44 @@
end
end

describe OrderedHash, "to_s" do
before do
@oh = OrderedHash.new
@oh["color"] = "red"
@oh["font"] = "x-small"
end

it "should list the styles" do
@oh.to_s.should == "color:red;font:x-small"
end
end

describe OrderedHash, "split" do
before do
@oh = OrderedHash.new
@oh["color"] = "red"
@oh["font"] = "x-small"

@split_hash = @oh.split("color")
end

describe "split hash" do
it "should contain split key" do
@split_hash["color"].should == "red"
end
it "should not contain non-split key" do
@split_hash.key?("font").should == false
end
end

describe "original hash" do
it "should not contain split key" do
@oh.key?("color").should == false
end
it "should contain non-split key" do
@oh["font"].should == "x-small"
end
end

end

2 changes: 1 addition & 1 deletion tiny_css.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "tiny_css"
s.version = "0.0.2"
s.version = "0.1.0"
s.date = "2008-07-10"
s.summary = ""
s.email = "info@milk1000.cc"
Expand Down

0 comments on commit 66e47ba

Please sign in to comment.