sugar-high 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/sugar-high/hash.rb +11 -0
- data/lib/sugar-high/path.rb +14 -0
- data/spec/sugar-high/hash_spec.rb +24 -0
- data/spec/sugar-high/path_spec.rb +16 -1
- data/sugar-high.gemspec +4 -2
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.9
|
data/lib/sugar-high/hash.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
require 'sugar-high/arguments'
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
def hash_revert
|
3
5
|
r = Hash.new {|h,k| h[k] = []}
|
4
6
|
each {|k,v| r[v] << k}
|
5
7
|
r
|
8
|
+
end
|
9
|
+
|
10
|
+
def try_keys *keys
|
11
|
+
option = last_option keys
|
12
|
+
keys.flatten.each do |key|
|
13
|
+
return self[key] if self[key]
|
14
|
+
end
|
15
|
+
return option[:default] if option[:default]
|
16
|
+
nil
|
6
17
|
end
|
7
18
|
end
|
data/lib/sugar-high/path.rb
CHANGED
@@ -25,6 +25,20 @@ module PathString
|
|
25
25
|
('../' * lv) + self
|
26
26
|
end
|
27
27
|
|
28
|
+
def post_up lv
|
29
|
+
self + ('/..' * lv)
|
30
|
+
end
|
31
|
+
|
32
|
+
def post_down lv
|
33
|
+
up_dir = Regexp.escape('/..')
|
34
|
+
orig = self.clone
|
35
|
+
lv.times do
|
36
|
+
self.gsub! /#{up_dir}$/, ''
|
37
|
+
return self if self == orig
|
38
|
+
end
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
28
42
|
def down lv
|
29
43
|
up_dir = Regexp.escape('../')
|
30
44
|
orig = self.clone
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/hash'
|
3
|
+
|
4
|
+
describe "SugarHigh" do
|
5
|
+
describe "Hash packet" do
|
6
|
+
describe '#hash_revert' do
|
7
|
+
it "should revert hash" do
|
8
|
+
{:a => 'hello', :b => 'hi', :c => 'hi'}.hash_revert.should == {'hello' => [:a], 'hi' => [:b, :c]}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should try keys in hash until triggered" do
|
12
|
+
{:a => 'hello', :b => 'hi'}.try_keys([:x, :a, :b]).should == 'hello'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return nil if no key triggered" do
|
16
|
+
{:a => 'hello', :b => 'hi'}.try_keys([:x, :y, :z]).should == nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil if no key triggered" do
|
20
|
+
{:a => 'hello', :b => 'hi'}.try_keys([:x, :y, :z], :default => 'none').should == 'none'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -14,12 +14,20 @@ end
|
|
14
14
|
|
15
15
|
describe 'PathString' do
|
16
16
|
describe '#up' do
|
17
|
-
it "should go up two folder levels" do
|
17
|
+
it "should go up two folder levels before path" do
|
18
18
|
up_path = "a/b/c".path.up(2)
|
19
19
|
up_path.should == "../../a/b/c"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
describe '#post_up' do
|
24
|
+
it "should go up two folder levels at end of path" do
|
25
|
+
up_path = "a/b/c".path.post_up(2)
|
26
|
+
up_path.should == "a/b/c/../.."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
23
31
|
describe '#down' do
|
24
32
|
it "should go down two folder levels" do
|
25
33
|
dwn_path = "../../a/b/c".path.down(2)
|
@@ -27,6 +35,13 @@ describe 'PathString' do
|
|
27
35
|
end
|
28
36
|
end
|
29
37
|
|
38
|
+
describe '#down' do
|
39
|
+
it "should go down two folder levels at end of path" do
|
40
|
+
dwn_path = "a/b/c/../..".path.post_down(2)
|
41
|
+
dwn_path.should == "a/b/c"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
describe '#exists?' do
|
31
46
|
it "should be true that this spec file exist" do
|
32
47
|
"#{__FILE__}".path.exists?.should be_true
|
data/sugar-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar-high}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -50,6 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
"spec/sugar-high/blank_spec.rb",
|
51
51
|
"spec/sugar-high/file/file_mutate_spec.rb",
|
52
52
|
"spec/sugar-high/file/file_spec.rb",
|
53
|
+
"spec/sugar-high/hash_spec.rb",
|
53
54
|
"spec/sugar-high/includes_spec.rb",
|
54
55
|
"spec/sugar-high/kind_of_spec.rb",
|
55
56
|
"spec/sugar-high/methods_spec.rb",
|
@@ -71,6 +72,7 @@ Gem::Specification.new do |s|
|
|
71
72
|
"spec/sugar-high/blank_spec.rb",
|
72
73
|
"spec/sugar-high/file/file_mutate_spec.rb",
|
73
74
|
"spec/sugar-high/file/file_spec.rb",
|
75
|
+
"spec/sugar-high/hash_spec.rb",
|
74
76
|
"spec/sugar-high/includes_spec.rb",
|
75
77
|
"spec/sugar-high/kind_of_spec.rb",
|
76
78
|
"spec/sugar-high/methods_spec.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 9
|
9
|
+
version: 0.2.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-17 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- spec/sugar-high/blank_spec.rb
|
108
108
|
- spec/sugar-high/file/file_mutate_spec.rb
|
109
109
|
- spec/sugar-high/file/file_spec.rb
|
110
|
+
- spec/sugar-high/hash_spec.rb
|
110
111
|
- spec/sugar-high/includes_spec.rb
|
111
112
|
- spec/sugar-high/kind_of_spec.rb
|
112
113
|
- spec/sugar-high/methods_spec.rb
|
@@ -154,6 +155,7 @@ test_files:
|
|
154
155
|
- spec/sugar-high/blank_spec.rb
|
155
156
|
- spec/sugar-high/file/file_mutate_spec.rb
|
156
157
|
- spec/sugar-high/file/file_spec.rb
|
158
|
+
- spec/sugar-high/hash_spec.rb
|
157
159
|
- spec/sugar-high/includes_spec.rb
|
158
160
|
- spec/sugar-high/kind_of_spec.rb
|
159
161
|
- spec/sugar-high/methods_spec.rb
|