duffy 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30abd81a96488a7b9d459dedaba4024d34955ba6
4
- data.tar.gz: aad43f04f7da8249f5244ff88381d535c4f695fc
3
+ metadata.gz: 6e4de5df8e2616ebcf7cb6c6152a1786f5871124
4
+ data.tar.gz: ef2bbf68bdd6ae2d1d118d7404d246d82e740acd
5
5
  SHA512:
6
- metadata.gz: 109756b56bfb368056ecc9a494bee298b8106daa01222f9249bc1eb7d22079a81ae6387f30994c7b946ab2f810dd02ae7a81c51ca0ab7e1679d6b1e268585152
7
- data.tar.gz: d6a13b599b0c1842b904eb65e64e7f78306398898ffc89e23838802da23f91c0166a8cc0cb8c6cd3b5c1ccbca57cdce58aefb4ae56f4013c098cb7237bf78f46
6
+ metadata.gz: 6a95acc1e49a85e7d08a33c62fcb8f49728d8a217877ce080c01b7cc56072c3bb0a26acd9d2e92bdc0c432ca2a17baf85767003302de7a29b0c521b27e85b61d
7
+ data.tar.gz: e16065af26004a1c8dc1f1aeddd1c288b2fd92538ce00819b2937923d0fcf0aa8f4c7a90cda415018eadad6f128875d889114cfc7cfe1f20d4ae5678cb7b1772
data/lib/duffy/git.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Duffy
2
+
3
+ # I like to have a git log in the admin section of my websites. I use these in my capistrano tasks to
4
+ # generate what I need and upload along with the deployment.
5
+
6
+ class Git
7
+ class << self
8
+
9
+ # Produce tab separated listing of current git log.
10
+ # Useful for displaying a development history page.
11
+ def log
12
+ `git log --pretty=format:"%ad%x09%an%x09%s" --date=short`
13
+ end
14
+
15
+ # I tend use the commit count / 1000.0 as a version for my applications.
16
+ # You wouldn't want to do that if you're building a gem used by others.
17
+ def count
18
+ `git rev-list HEAD --count`
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,133 @@
1
+ # Monkey Patch String adding useful methods.
2
+ class String
3
+
4
+ def to_ssn
5
+ ssn = self.to_s.gsub(/[^0-9]/, "") # now it's a string with only 0-9
6
+ ssn = "%09d" % ssn # now it has leading zeros
7
+ ssn[0..2] + "-" + ssn[3..4] + "-" + ssn[5..8] # now it's like 123-45-6789
8
+ end
9
+
10
+ # Sanitize SSN.
11
+ #
12
+ # "123456789" => "123456789" # Good
13
+ # "123-45-6789" => "123456789" # Good
14
+ # "000-12-3456" => nil # Invalid Area
15
+ # "666123456" => nil # Invalid Area
16
+ # "derp" => nil # Bogus
17
+ # "123456" => nil # Too short ( becomes 000123456: Invalid Area )
18
+ # "999999999" => nil # Important. Many HRS entries
19
+ # "-" => nil # Important. Many HRS entries
20
+ #
21
+ # http://www.ssa.gov/history/ssn/geocard.html
22
+ # http://en.wikipedia.org/wiki/Social_Security_number
23
+ # area: 001 to 665, 667 to 899
24
+ # group: 01 to 99.
25
+ # serial: 0001 to 9999
26
+ def sanitize_ssn
27
+ begin
28
+ ssn = "%09d" % self.to_numeric
29
+ raise "Too Long" if ssn.length > 9
30
+ area, group, serial = ssn[0..2], ssn[3..4], ssn[5..8]
31
+ raise "Area Range Invalid" unless ("001" .. "665").cover?(area) or ("667" .. "899").cover?(area)
32
+ raise "Group Range Invalid" unless ("01" .. "99").cover?(group)
33
+ raise "Serial Range Invalid" unless ("0001" .. "9999").cover?(serial)
34
+ rescue
35
+ return nil
36
+ end
37
+ ssn
38
+ end
39
+
40
+ def to_numeric
41
+ self.to_s.gsub(/[^0-9]/, "") # now it's a string with only 0-9
42
+ end
43
+
44
+ def to_alpha
45
+ self.to_s.gsub(/[^a-zA-Z ]/, "").strip # string with only a-z or A-Z or space, leading+trailing whitespace removed
46
+ end
47
+
48
+ def to_alpha_numeric
49
+ self.to_s.gsub(/[^0-9a-zA-Z ]/, "").strip # string with only a-z or A-Z or space, leading+trailing whitespace removed
50
+ end
51
+
52
+
53
+ def pretty_phone
54
+ number = self.to_s.gsub(/[^0-9\+]/, "")
55
+ return "(" + number[0..2] + ") " + number[3..5] + "-" + number[6..9] if number.length == 10
56
+ number
57
+ end
58
+
59
+ # Parse a git username into a friendly name
60
+ def pretty_committer
61
+ case self
62
+ when /jpd/ then "Jacob"
63
+ when /ers|Eric/ then "Eric"
64
+ when /gac/ then "Glenn"
65
+ when /jes/ then "Samsky"
66
+ else self
67
+ end
68
+ end
69
+
70
+ def space2nbsp
71
+ # turns double space to double nbsp
72
+ (self.nil?)? "" : self.to_s.gsub(/ {2}/, "&nbsp;&nbsp;").html_safe
73
+ end
74
+
75
+ def nl2br
76
+ (self.nil?)? "" : self.to_s.gsub(/(\r)?\n/, "<br />").html_safe
77
+ end
78
+
79
+
80
+ def gender_human
81
+ case (self.to_s.upcase)
82
+ when "M" then "Male"
83
+ when "F" then "Female"
84
+ when "O" then "Other"
85
+ else ""
86
+ end
87
+ end
88
+
89
+
90
+ # Smarter Titlecase function.
91
+ # Examples:
92
+ # "foo" => "Foo"
93
+ # "IMPORTANT STUFF" => "Important Stuff"
94
+ # "123 main st." => "123 Main St."
95
+ # "a tale of two cities" => "A Tale of Two Cities"
96
+ def smart_titlecase
97
+ small_re = %w( is a an and as at but by en for if in of on or the to v[.]? via vs[.]? ).join('|')
98
+
99
+ # Original Perl version by: John Gruber (daringfireball.net) 2008-05-10
100
+ # Adapted to Ruby by: Marshall Elfstrand (vengefulcow.com/ 2008-05-21
101
+ # Improved and customized: Jacob Duffy (duffy.jp) 2011-01-25
102
+ # License: http://www.opensource.org/licenses/mit-license.php
103
+
104
+ # if source is all uppercase, use all lowercase instead. -- jpd
105
+ string = (self.upcase == self)? self.downcase : self
106
+
107
+ result = ""
108
+ string.gsub(/[_-]/, ' ').split(/( [:.;?!][ ] | (?:[ ]|^)[""] )/x).each do |s|
109
+ s.gsub!(/ \b( [[:alpha:]] [[:lower:].'']* )\b /x) do |w|
110
+ # Skip words with inresult dots, e.g. "del.icio.us" or "example.com"
111
+ (w =~ / [[:alpha:]] [.] [[:alpha:]] /x) ? w : w.capitalize
112
+ end #gsub!
113
+
114
+ # Lowercase our list of small words:
115
+ s.gsub!(/\b(#{small_re})\b/io) { |w| w.downcase }
116
+
117
+ # If the first word in the title is a small word, then capitalize it:
118
+ s.gsub!(/\A([[:punct:]]*)(#{small_re})\b/io) { |w| $1 + $2.capitalize }
119
+
120
+ # If the last word in the title is a small word, then capitalize it:
121
+ s.gsub!(/\b(#{small_re})([[:punct:]]*)\Z/io) { |w| $1.capitalize + $2 }
122
+
123
+ # Append current substring to output
124
+ result += s
125
+ end #each
126
+
127
+ # Special Cases:
128
+ result.gsub!(/ V(s?)\. /, ' v\1. ') # "v." and "vs."
129
+ result.gsub!(/([''])S\b/, '\1s') # 'S (otherwise you get "the SEC'S decision")
130
+ result.gsub!(/\b(AOB|AT&T|Q&A|II|III|IV|HR|CT|CHS|CME|HRS|PA|UDDS|USA|UWMF|WREN)\b/i) { |w| w.upcase } # "AT&T" and "Q&A", which get tripped up by
131
+ result
132
+ end
133
+ end
data/lib/duffy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Duffy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/duffy.rb CHANGED
@@ -1,29 +1,3 @@
1
- require "duffy/version"
2
-
3
- module Duffy
4
-
5
-
6
- # I like to have a git log in the admin section of my websites. I use these in my capistrano tasks to
7
- # generate what I need and upload along with the deployment.
8
-
9
- class Git
10
- class << self
11
-
12
- # Produce tab separated listing of current git log.
13
- # Useful for displaying a development history page.
14
- def log
15
- `git log --pretty=format:"%ad%x09%an%x09%s" --date=short`
16
- end
17
-
18
- # I tend use the commit count / 1000.0 as a version for my applications.
19
- # You wouldn't want to do that if you're building a gem used by others.
20
- def count
21
- `git rev-list HEAD --count`
22
- end
23
-
24
- end
25
- end
26
-
27
-
28
-
29
- end
1
+ require File.dirname(__FILE__) + "/duffy/version"
2
+ require File.dirname(__FILE__) + "/duffy/git"
3
+ require File.dirname(__FILE__) + "/duffy/string"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
@@ -52,6 +52,8 @@ files:
52
52
  - Rakefile
53
53
  - duffy.gemspec
54
54
  - lib/duffy.rb
55
+ - lib/duffy/git.rb
56
+ - lib/duffy/string.rb
55
57
  - lib/duffy/version.rb
56
58
  homepage: https://github.com/duffyjp/duffy
57
59
  licenses: