beenverified_extensions 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/beenverified_extensions.gemspec +24 -0
- data/lib/beenverified_extensions.rb +3 -0
- data/lib/beenverified_extensions/all.rb +5 -0
- data/lib/beenverified_extensions/array.rb +5 -0
- data/lib/beenverified_extensions/date.rb +19 -0
- data/lib/beenverified_extensions/hash.rb +30 -0
- data/lib/beenverified_extensions/nil_class.rb +5 -0
- data/lib/beenverified_extensions/string.rb +11 -0
- data/lib/beenverified_extensions/version.rb +3 -0
- data/spec/array_spec.rb +22 -0
- data/spec/date_spec.rb +46 -0
- data/spec/hash_spec.rb +22 -0
- data/spec/nil_spec.rb +18 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/string_spec.rb +22 -0
- metadata +112 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: acd669526517d3038589dc9f2961893ed75a0bd0
|
|
4
|
+
data.tar.gz: 86ebd7bf4de57665bb0725d4f8d13003e855cfa6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f6369f0d3153b92efa494f9de2f0c01ce70c1f45ea6afa74bdcd1ee3ed9f9c7ba7b209380af1bddfd0aac2aa485ecc1dab4ebb989373d1256fa4f4899c14165d
|
|
7
|
+
data.tar.gz: c75a1cf5bc5f03f3fba068e716f9c93e3a4811d70e78b4d4e5bf7ce1d5d59f24a80fe9211662262cb2c45f67a9b9efe5623ed5c59fcef6f8a79bf21d2b247e07
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Patrick Tulskie
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# BeenverifiedExtensions
|
|
2
|
+
|
|
3
|
+
A gem full of wonderful extensions used in our various applications at BeenVerified.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'beenverified_extensions'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install beenverified_extensions
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
You can use as much or as little as you want from this gem.
|
|
22
|
+
|
|
23
|
+
Load it all up like this:
|
|
24
|
+
|
|
25
|
+
require "beenverified_extensions/all"
|
|
26
|
+
|
|
27
|
+
Load up specific peices like this:
|
|
28
|
+
|
|
29
|
+
require "beenverified_extensions/array"
|
|
30
|
+
require "beenverified_extensions/date"
|
|
31
|
+
require "beenverified_extensions/hash"
|
|
32
|
+
require "beenverified_extensions/nil_class"
|
|
33
|
+
require "beenverified_extensions/string"
|
|
34
|
+
|
|
35
|
+
## Contributing
|
|
36
|
+
|
|
37
|
+
1. Fork it
|
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
41
|
+
5. Create new Pull Request
|
|
42
|
+
|
|
43
|
+
Make sure that you include tests. We use minitest. You can run all of the specs with `rake test`
|
data/Rakefile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'beenverified_extensions/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "beenverified_extensions"
|
|
8
|
+
spec.version = BeenverifiedExtensions::VERSION
|
|
9
|
+
spec.authors = ["Patrick Tulskie"]
|
|
10
|
+
spec.email = ["patricktulskie@gmail.com"]
|
|
11
|
+
spec.description = %q{A collection of extensions we use at BeenVerified}
|
|
12
|
+
spec.summary = %q{Extensions to a variety of built in Ruby classes}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
spec.add_development_dependency "minitest"
|
|
24
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class Date
|
|
2
|
+
def self.days_between(start, finish)
|
|
3
|
+
(finish - start).to_i
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.weeks_between(start, finish)
|
|
7
|
+
days_between(start, finish) / 7
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.months_between(start, finish)
|
|
11
|
+
(finish.year * 12 + finish.month) - (start.year * 12 + start.month)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.years_between(start, finish)
|
|
15
|
+
difference = finish.year - start.year
|
|
16
|
+
difference -= 1 if difference > 0 && (finish.month < start.month || finish.day < start.day)
|
|
17
|
+
difference
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Hash
|
|
2
|
+
|
|
3
|
+
def arrayify
|
|
4
|
+
[self]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def to_query_string(escape_string=false)
|
|
8
|
+
if escape_string
|
|
9
|
+
URI.escape(self.reject{ |k,v| v=="" }.map{ |k,v| "#{k.to_s}=#{v.to_s.gsub(%r{\s},'+')}" }.join("&"))
|
|
10
|
+
else
|
|
11
|
+
self.reject{ |k,v| v == "" }.map{ |k,v| "#{k.to_s}=#{v.to_s.gsub(%r{\s},'+')}" }.join("&")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def rename_key(old_key, new_key)
|
|
16
|
+
return Hash.rename_key(self.dup, old_key, new_key)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def rename_key!(old_key, new_key)
|
|
20
|
+
return Hash.rename_key(self, old_key, new_key)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def self.rename_key(hsh, old_key, new_key)
|
|
26
|
+
hsh[new_key.to_s] = hsh.delete(old_key.to_s)
|
|
27
|
+
return hsh
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
data/spec/array_spec.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Array do
|
|
4
|
+
|
|
5
|
+
describe :instance do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@array = ['something']
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "responds to arrayify" do
|
|
12
|
+
@array.must_respond_to(:arrayify)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns itself" do
|
|
16
|
+
@array.arrayify.must_be_instance_of Array
|
|
17
|
+
@array.arrayify.must_equal @array
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
data/spec/date_spec.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require_relative "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Date do
|
|
4
|
+
|
|
5
|
+
describe :class do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@start_date = Date.parse("August 1st, 1985")
|
|
9
|
+
@end_date = Date.parse("August 1st, 1986")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "responds to days_between" do
|
|
13
|
+
Date.must_respond_to :days_between
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "responds to weeks_between" do
|
|
17
|
+
Date.must_respond_to :weeks_between
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "responds to months_between" do
|
|
21
|
+
Date.must_respond_to :months_between
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "responds to years_between" do
|
|
25
|
+
Date.must_respond_to :years_between
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "calculates days_between" do
|
|
29
|
+
Date.days_between(@start_date, @end_date).must_equal 365
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "calculates weeks_between" do
|
|
33
|
+
Date.weeks_between(@start_date, @end_date).must_equal 52
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "calculates months between" do
|
|
37
|
+
Date.months_between(@start_date, @end_date).must_equal 12
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "calculates years between" do
|
|
41
|
+
Date.years_between(@start_date, @end_date).must_equal 1
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
data/spec/hash_spec.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Hash do
|
|
4
|
+
|
|
5
|
+
describe :instance do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@hash = { :key => 'value' }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "responds to arrayify" do
|
|
12
|
+
@hash.must_respond_to(:arrayify)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns a hash wrapped in an array" do
|
|
16
|
+
@hash.arrayify.must_be_instance_of Array
|
|
17
|
+
@hash.arrayify.first.must_equal @hash
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
data/spec/nil_spec.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe NilClass do
|
|
4
|
+
|
|
5
|
+
describe :instance do
|
|
6
|
+
|
|
7
|
+
it "responds to arrayify" do
|
|
8
|
+
nil.must_respond_to(:arrayify)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "returns an empty array" do
|
|
12
|
+
nil.arrayify.must_be_instance_of Array
|
|
13
|
+
nil.arrayify.must_equal [ ]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/string_spec.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe String do
|
|
4
|
+
|
|
5
|
+
describe :instance do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@string = "string"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "responds to arrayify" do
|
|
12
|
+
@string.must_respond_to(:arrayify)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "returns a string wrapped in an array" do
|
|
16
|
+
@string.arrayify.must_be_instance_of Array
|
|
17
|
+
@string.arrayify.first.must_equal @string
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: beenverified_extensions
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Patrick Tulskie
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-12-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.3'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.3'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - '>='
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - '>='
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: A collection of extensions we use at BeenVerified
|
|
56
|
+
email:
|
|
57
|
+
- patricktulskie@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- beenverified_extensions.gemspec
|
|
68
|
+
- lib/beenverified_extensions.rb
|
|
69
|
+
- lib/beenverified_extensions/all.rb
|
|
70
|
+
- lib/beenverified_extensions/array.rb
|
|
71
|
+
- lib/beenverified_extensions/date.rb
|
|
72
|
+
- lib/beenverified_extensions/hash.rb
|
|
73
|
+
- lib/beenverified_extensions/nil_class.rb
|
|
74
|
+
- lib/beenverified_extensions/string.rb
|
|
75
|
+
- lib/beenverified_extensions/version.rb
|
|
76
|
+
- spec/array_spec.rb
|
|
77
|
+
- spec/date_spec.rb
|
|
78
|
+
- spec/hash_spec.rb
|
|
79
|
+
- spec/nil_spec.rb
|
|
80
|
+
- spec/spec_helper.rb
|
|
81
|
+
- spec/string_spec.rb
|
|
82
|
+
homepage: ''
|
|
83
|
+
licenses:
|
|
84
|
+
- MIT
|
|
85
|
+
metadata: {}
|
|
86
|
+
post_install_message:
|
|
87
|
+
rdoc_options: []
|
|
88
|
+
require_paths:
|
|
89
|
+
- lib
|
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - '>='
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - '>='
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
100
|
+
requirements: []
|
|
101
|
+
rubyforge_project:
|
|
102
|
+
rubygems_version: 2.0.6
|
|
103
|
+
signing_key:
|
|
104
|
+
specification_version: 4
|
|
105
|
+
summary: Extensions to a variety of built in Ruby classes
|
|
106
|
+
test_files:
|
|
107
|
+
- spec/array_spec.rb
|
|
108
|
+
- spec/date_spec.rb
|
|
109
|
+
- spec/hash_spec.rb
|
|
110
|
+
- spec/nil_spec.rb
|
|
111
|
+
- spec/spec_helper.rb
|
|
112
|
+
- spec/string_spec.rb
|