duffy 1.0.6 → 1.0.7

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
  SHA256:
3
- metadata.gz: 7b26949061663fcfd666bc4479d89671494dfc81d2e14a3bb3189970de202255
4
- data.tar.gz: e8dc1912140fc07fb39c4f9d15070c26397d91b9cd63fdaa7fc164e889e4cf5c
3
+ metadata.gz: fb1c4a1481cef7c25c9126237c88660ca2f9953133937348e238e3112bbfde3f
4
+ data.tar.gz: fc41ae17543a60627d4470deeb0677df595876bd33171212e22a42f3cc17bb93
5
5
  SHA512:
6
- metadata.gz: 2816bf8e70c972cc7ce9e3066f8d54d9c93cb8e00958e2bd7ada8ab060163958faaeff52ca973af982039994acdcef6a0148b907d2193976ed4cbcf0787bfa11
7
- data.tar.gz: '065851c6e0a9e97533715eef0800390cd0811c2ecc3453871479be7fb9d85056fbdc4327c54cbf4555819e5aa81b5f82c1007cd94525c316c17bb905f980dae0'
6
+ metadata.gz: e10dc97feccbeb7a5e9b5bfd6ed5bd0bb857f57ba0be4181595d2a30e4178db32deab797b4796a9bd3485ddea482354db8015e714796bf3234b2aed156cff7be
7
+ data.tar.gz: '08764e0a764d564c26389d53f42704ad1f646bab2b7614205eb358cc1d11cfd177e213b0499d869f8ad0a156f9eeed82c72cf2748fd64168b5217b61c30447fe'
data/README.md CHANGED
@@ -17,21 +17,21 @@ $ bundle
17
17
 
18
18
  ## String Patches:
19
19
 
20
- Method | Example | Output
21
- ------------------|-----------------|-------
22
- gender_human | "F" | "Female"
23
- md5 | "duffy" | "904bc6e21e4799ce276200117215b88b"
24
- md5sum | "duffy" | "904bc6e21e4799ce276200117215b88b"
25
- nl2br | "space\nout" | "space<br/>out" (requires rails)
26
- pretty_phone | "1234567890" | "(123) 456-7890"
27
- pretty_committer | "bart" | "Bartholomew Simpson" (See config)
28
- smart_titlecase | "this and that" | "This and That" (Note: Has config options. See lib/duffy.rb)
29
- space2nbsp | "space out" | "space&nbsp;out" (requires rails)
30
- to_alpha | "abc123" | "abc"
31
- to_alpha_numeric | "abc#$%123" | "abc123
32
- to_box | "abc".to_box | ![Example](doc/abc.png)
33
- to_numeric | "abc123" | "123"
34
- to_ssn | "123456789" | "123-45-6789"
20
+ Method | Example | Output | Notes
21
+ ------------------|------------------|------------------------------------|------
22
+ gender_human | "F" | "Female" |
23
+ md5 | "duffy" | "904bc6e21e4799ce276200117215b88b" |
24
+ md5sum | "duffy" | "904bc6e21e4799ce276200117215b88b" |
25
+ nl2br | "space\nout" | "space<br/>out" | various OS newline permutations
26
+ pretty_phone | "1234567890" | "(123) 456-7890" | US phone number with or without area code
27
+ pretty_committer | "bart" | "Bartholomew Simpson" | See config
28
+ smart_titlecase | "this and that" | "This and That" | Has config options. See lib/duffy.rb
29
+ space2nbsp | "space out" | "space&nbsp;&nbsp;out" | Double space holdouts rejoice.
30
+ to_alpha | "abc123" | "abc" |
31
+ to_alpha_numeric | "abc#$%123" | "abc123 |
32
+ to_box | "abc".to_box | ![Example](doc/abc.png) |
33
+ to_numeric | "abc123" | "123" |
34
+ to_ssn | "123456789" | "123-45-6789" |
35
35
 
36
36
 
37
37
  ## Array Patches:
data/lib/duffy/string.rb CHANGED
@@ -76,12 +76,15 @@ class String
76
76
  end
77
77
 
78
78
  def space2nbsp
79
- # turns double space to double nbsp
80
- (self.nil?)? "" : self.to_s.gsub(/ {2}/, "&nbsp;&nbsp;").html_safe
79
+ # turns >= double space to double nbsp
80
+ string = (self.nil?)? "" : self.to_s.gsub(/ {2,}/, "&nbsp;&nbsp;")
81
+ defined?(html_safe) ? string.html_safe : string
81
82
  end
82
83
 
84
+ # Replace the various combinations of newline characters with HTML <br> tags.
83
85
  def nl2br
84
- (self.nil?)? "" : self.to_s.gsub(/(\r)?\n/, "<br />").html_safe
86
+ string = (self.nil?)? "" : self.to_s.gsub(/(\r\n)|(\n\r)|\n|\v/, "<br>")
87
+ defined?(html_safe) ? string.html_safe : string
85
88
  end
86
89
 
87
90
 
data/lib/duffy/version.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Duffy
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
4
4
 
5
5
  # History
6
+ # 1.0.7 - Added vertical tab to list of characters replace with <br> in nl2br.
6
7
  # 1.0.6 - Add to_markdown Array method.
7
8
  # 1.0.5 - Update smart_titlecase to better accommodate names.
8
9
  # 1.0.4 - Added battery_percent method.
data/spec/string_spec.rb CHANGED
@@ -8,6 +8,39 @@ describe String do
8
8
  end
9
9
  end
10
10
 
11
+ describe "nl2br" do
12
+ it "converts linux newlines" do
13
+ expect("This\nand\nthat.".nl2br).to eq "This<br>and<br>that."
14
+ end
15
+ it "converts windows newlines" do
16
+ expect("This\r\nand\r\nthat.".nl2br).to eq "This<br>and<br>that."
17
+ end
18
+ it "converts backwards windows newlines" do
19
+ expect("This\n\rand\n\rthat.".nl2br).to eq "This<br>and<br>that."
20
+ end
21
+
22
+ it "converts vertical tabs from dubious software newlines" do
23
+ expect("This\vand\vthat.".nl2br).to eq "This<br>and<br>that."
24
+ end
25
+
26
+ it "slash R slash N slash N becomes <br><br>" do
27
+ expect("This\r\n\nthat.".nl2br).to eq "This<br><br>that."
28
+ end
29
+
30
+ it "slash N slash R slash N becomes <br><br>" do
31
+ expect("This\n\r\nthat.".nl2br).to eq "This<br><br>that."
32
+ end
33
+
34
+ it "slash N slash N slash R becomes <br><br>" do
35
+ expect("This\n\n\rthat.".nl2br).to eq "This<br><br>that."
36
+ end
37
+
38
+ it "slash N slash N slash N becomes <br><br><br>" do
39
+ expect("This\n\n\nthat.".nl2br).to eq "This<br><br><br>that."
40
+ end
41
+ end
42
+
43
+
11
44
  describe "pretty_phone" do
12
45
  it "formats an American phone number with Area Code" do
13
46
  expect("1234567890".pretty_phone).to eq "(123) 456-7890"
@@ -26,6 +59,21 @@ describe String do
26
59
  end
27
60
  end
28
61
 
62
+ describe "space2nbsp" do
63
+
64
+ it "leaves single space alone" do
65
+ expect("1 1".space2nbsp).to eq "1 1"
66
+ end
67
+
68
+ it "turns double space to double nbsp" do
69
+ expect("1 2".space2nbsp).to eq "1&nbsp;&nbsp;2"
70
+ end
71
+
72
+ it "turns triple space to double nbsp" do
73
+ expect("1 3".space2nbsp).to eq "1&nbsp;&nbsp;3"
74
+ end
75
+ end
76
+
29
77
  describe "smart_titlecase" do
30
78
  {
31
79
  "123 Main St." => "123 Main St.", # Numbers are allowed
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duffy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2023-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.2.32
158
+ rubygems_version: 3.4.10
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Library of things