beefup 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/lib/beef/core_ext/fixnum.rb +1 -0
- data/lib/beef/core_ext/fixnum/to_boolean.rb +11 -0
- data/lib/beef/core_ext/hash.rb +2 -1
- data/lib/beef/core_ext/hash/array_access.rb +23 -0
- data/lib/beef/core_ext/nil_class.rb +1 -0
- data/lib/beef/core_ext/nil_class/arrayify.rb +7 -0
- data/lib/beef/version.rb +1 -1
- data/spec/beef/core_ext/fixnum_spec.rb +17 -0
- data/spec/beef/core_ext/hash_spec.rb +22 -0
- data/spec/beef/core_ext/nil_class_spec.rb +10 -0
- data/spec/beef/core_ext/string_spec.rb +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb4330631738c32173a3b6b82ee7925418b5a350
|
4
|
+
data.tar.gz: 2eea3b965ef479118db5a24732bbae46d9e2d745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e917c56dc866bde551d74c32911a2e1e7860722fc7d045d9bd0631eb459c6cdff6c677f18d74295f99577ca808bbf1c541ab88c4afe6f8ac2b75553b2becb6
|
7
|
+
data.tar.gz: a8003abcb6843279a2a203d418c9af4b96566367e9e9516760e094e2265425c0253598ac83ea42690f33866f89ba56b97d511f385f1c6ba2f1419bc91b03921a
|
data/README.md
CHANGED
@@ -50,6 +50,22 @@ Smarter titleising of a string which ignores certain words (E.g an, a, is, of, e
|
|
50
50
|
```ruby
|
51
51
|
"is this an original string? yes it is".titleise
|
52
52
|
=> "Is This an Original String? Yes It Is"
|
53
|
+
|
54
|
+
"this is a title".titleise
|
55
|
+
=> "This is a Title"
|
56
|
+
```
|
57
|
+
|
58
|
+
### Fixnum
|
59
|
+
|
60
|
+
#### To Boolean
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
1.to_boolean
|
64
|
+
=> true
|
65
|
+
0.to_b
|
66
|
+
=> false
|
67
|
+
25.to_b
|
68
|
+
=> true
|
53
69
|
```
|
54
70
|
|
55
71
|
### Hash
|
@@ -90,6 +106,17 @@ Recursively merge two hashes
|
|
90
106
|
=> { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => { :c2a => "c2a", :c2b => "c2b" } } }
|
91
107
|
```
|
92
108
|
|
109
|
+
#### Array Access
|
110
|
+
|
111
|
+
Access a nested Hash element with a given array depicting the path
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
hash = { :a => {:b => {:c => { :d => "Value" } } } }
|
115
|
+
array = [:a, :b, :c, :d]
|
116
|
+
hash.access_by_array(array)
|
117
|
+
=> "Value"
|
118
|
+
```
|
119
|
+
|
93
120
|
## Contributing
|
94
121
|
|
95
122
|
1. Fork it
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'beef/core_ext/fixnum/to_boolean'
|
data/lib/beef/core_ext/hash.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
# Access nested element with a given array of keys depciting the path
|
4
|
+
def access_by_array(key_array)
|
5
|
+
return nil unless key_array.is_a? Array
|
6
|
+
current_element = self
|
7
|
+
key_array.each do |key|
|
8
|
+
if current_element.is_a? Hash
|
9
|
+
current_element = current_element[key]
|
10
|
+
else
|
11
|
+
current_element = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
current_element
|
16
|
+
end
|
17
|
+
|
18
|
+
# Coming soon
|
19
|
+
# def set_by_array(key_array, value)
|
20
|
+
# access_by_array(key_array)
|
21
|
+
# end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'beef/core_ext/nil_class/arrayify'
|
data/lib/beef/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'beef/core_ext/fixnum'
|
5
|
+
|
6
|
+
describe "Fixnum falsey" do
|
7
|
+
it "should return false when to_b is called" do
|
8
|
+
0.to_b.should be_false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Fixnum truthy" do
|
13
|
+
it "should return true when to_b is called" do
|
14
|
+
1.to_b.should be_true
|
15
|
+
20.to_b.should be_true
|
16
|
+
end
|
17
|
+
end
|
@@ -40,4 +40,26 @@ describe "Hash deep merge" do
|
|
40
40
|
@hash1.deep_merge!(@hash2)
|
41
41
|
@hash1.should == @expected_hash
|
42
42
|
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "Hash array access" do
|
46
|
+
before do
|
47
|
+
@hash = { :a => { :b => { :c => { :d => "Value" } } } }
|
48
|
+
@key_array = [:a, :b, :c, :d]
|
49
|
+
@key_array_fail = [:a, :b, :c, :d, :e]
|
50
|
+
@key_array_fail2 = [:a, :e, :c]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return correct value given an array of keys" do
|
54
|
+
@hash.access_by_array(@key_array).should == "Value"
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return nil given array of keys that is too long" do
|
58
|
+
@hash.access_by_array(@key_array_fail).should be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return nil given an invalid array of keys" do
|
62
|
+
@hash.access_by_array(@key_array_fail2).should be_nil
|
63
|
+
end
|
64
|
+
|
43
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beefup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,14 +68,21 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- beef.gemspec
|
70
70
|
- lib/beef.rb
|
71
|
+
- lib/beef/core_ext/fixnum.rb
|
72
|
+
- lib/beef/core_ext/fixnum/to_boolean.rb
|
71
73
|
- lib/beef/core_ext/hash.rb
|
74
|
+
- lib/beef/core_ext/hash/array_access.rb
|
72
75
|
- lib/beef/core_ext/hash/deep_merge.rb
|
73
76
|
- lib/beef/core_ext/hash/method_access.rb
|
77
|
+
- lib/beef/core_ext/nil_class.rb
|
78
|
+
- lib/beef/core_ext/nil_class/arrayify.rb
|
74
79
|
- lib/beef/core_ext/string.rb
|
75
80
|
- lib/beef/core_ext/string/titleise.rb
|
76
81
|
- lib/beef/core_ext/string/to_boolean.rb
|
77
82
|
- lib/beef/version.rb
|
83
|
+
- spec/beef/core_ext/fixnum_spec.rb
|
78
84
|
- spec/beef/core_ext/hash_spec.rb
|
85
|
+
- spec/beef/core_ext/nil_class_spec.rb
|
79
86
|
- spec/beef/core_ext/string_spec.rb
|
80
87
|
- spec/spec_helper.rb
|
81
88
|
homepage: http://simonjones.github.io/beef
|
@@ -102,6 +109,8 @@ signing_key:
|
|
102
109
|
specification_version: 4
|
103
110
|
summary: A Ruby core exntension library.
|
104
111
|
test_files:
|
112
|
+
- spec/beef/core_ext/fixnum_spec.rb
|
105
113
|
- spec/beef/core_ext/hash_spec.rb
|
114
|
+
- spec/beef/core_ext/nil_class_spec.rb
|
106
115
|
- spec/beef/core_ext/string_spec.rb
|
107
116
|
- spec/spec_helper.rb
|