small 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +5 -0
- data/lib/small.rb +10 -0
- data/lib/small/array.rb +10 -0
- data/lib/small/hash.rb +17 -0
- data/lib/small/math.rb +15 -0
- data/lib/small/object.rb +15 -0
- data/lib/small/string.rb +62 -0
- metadata +52 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Bryan Goines
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/lib/small.rb
ADDED
data/lib/small/array.rb
ADDED
data/lib/small/hash.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Hash
|
2
|
+
|
3
|
+
def stringify_keys!
|
4
|
+
keys.each {|key| self[key.to_s] = delete(key) }
|
5
|
+
self
|
6
|
+
end
|
7
|
+
|
8
|
+
def symbolize_keys!
|
9
|
+
keys.each {|key| self[key.to_sym] = delete(key) }
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_param
|
14
|
+
collect {|key, value| "#{key}=#{value}" }.sort * '&'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/small/math.rb
ADDED
data/lib/small/object.rb
ADDED
data/lib/small/string.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
def camelize
|
4
|
+
gsub(/\s+/, '_').gsub(/(?:^|_)(.)/) { $1.upcase }
|
5
|
+
end
|
6
|
+
|
7
|
+
def dashize
|
8
|
+
gsub(/_/, '-')
|
9
|
+
end
|
10
|
+
|
11
|
+
def humanize
|
12
|
+
gsub(/_/, ' ').gsub(/^(\w)/) { $1.upcase }
|
13
|
+
end
|
14
|
+
|
15
|
+
def underscore
|
16
|
+
gsub(/(-|\s+)/,'_').downcase
|
17
|
+
end
|
18
|
+
|
19
|
+
def constantize
|
20
|
+
constant = Object
|
21
|
+
constant.const_defined?(self.to_s) ? constant.const_get(self.to_s) : constant.const_missing(self.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def encode64
|
25
|
+
[self.to_s].pack("m").gsub(/\n/,'')
|
26
|
+
end
|
27
|
+
|
28
|
+
def decode64
|
29
|
+
unpack("m").first
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_sha1
|
33
|
+
require "digest/sha1" unless defined?(Digest::SHA1)
|
34
|
+
Digest::SHA1.hexdigest(self.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_sha2(provider = 256)
|
38
|
+
require 'digest/sha2' unless defined?(Digest::SHA256) || defined?(Digest::SHA384) || defined?(Digest::SHA512)
|
39
|
+
object = case provider
|
40
|
+
when 256 then Digest::SHA256.new
|
41
|
+
when 384 then Digest::SHA384.new
|
42
|
+
when 512 then Digest::SHA512.new
|
43
|
+
else raise Exception, "Unknown digest provider: #{provider} -- try 256, 384, and 512"
|
44
|
+
end
|
45
|
+
object.hexdigest(self.to_s)
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_md5
|
49
|
+
require 'digest/md5' unless defined?(Digest::MD5)
|
50
|
+
Digest::MD5.hexdigest(self.to_s)
|
51
|
+
end
|
52
|
+
|
53
|
+
def escape
|
54
|
+
require 'cgi' unless defined?(CGI)
|
55
|
+
CGI.escape(self.to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
def unescape
|
59
|
+
require 'cgi' unless defined?(CGI)
|
60
|
+
CGI.unescape(self.to_s)
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: small
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bryan Goines
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email: bryann83@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- LICENSE
|
22
|
+
- lib/small/array.rb
|
23
|
+
- lib/small/hash.rb
|
24
|
+
- lib/small/math.rb
|
25
|
+
- lib/small/object.rb
|
26
|
+
- lib/small/string.rb
|
27
|
+
- lib/small.rb
|
28
|
+
homepage: https://github.com/bry4n/small
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.15
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: A small collection of useful Ruby utilities
|
52
|
+
test_files: []
|