duffy 1.0.6 → 1.0.8

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: 8873a39ece2e7a2a8ffc4423da9c6fba6c64cade3fe11abebe3c3dd24f5a779d
4
+ data.tar.gz: 74b38171a364c3ad4fb7565df514ec89ffb71ef0b9fe34121081fc575811a8b1
5
5
  SHA512:
6
- metadata.gz: 2816bf8e70c972cc7ce9e3066f8d54d9c93cb8e00958e2bd7ada8ab060163958faaeff52ca973af982039994acdcef6a0148b907d2193976ed4cbcf0787bfa11
7
- data.tar.gz: '065851c6e0a9e97533715eef0800390cd0811c2ecc3453871479be7fb9d85056fbdc4327c54cbf4555819e5aa81b5f82c1007cd94525c316c17bb905f980dae0'
6
+ metadata.gz: 8b90e00f3af06dfc475f46f1d3890e4c045de21b4a3217cc64e497b96c45f9932450cc6febcea049d98800074ef45ab55e3f8474d1bc3d4aac96d488f24ab2bc
7
+ data.tar.gz: 6fc6f7af5dd48af01ff147edb8b2526f1b98cd32348a6651957f9c22c912968b7b7631873bb89024506f1bf13305c83a76da86ddcdc00f2e35e504ffe10b5553
@@ -6,7 +6,7 @@ jobs:
6
6
  fail-fast: false
7
7
  matrix:
8
8
  os: [ubuntu-latest, macos-latest]
9
- ruby: [2.6, 2.7, '3.0', 3.1]
9
+ ruby: [2.7, 3.0, 3.2, 3.4, 4.0]
10
10
  runs-on: ${{ matrix.os }}
11
11
  steps:
12
12
  - uses: actions/checkout@v2
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
@@ -63,6 +63,7 @@ class String
63
63
 
64
64
  def pretty_phone
65
65
  number = self.to_s.gsub(/[^0-9\+]/, "")
66
+ number = number[2..] if number.start_with?("+1") && number.length == 12
66
67
  return "(" + number[0..2] + ") " + number[3..5] + "-" + number[6..9] if number.length == 10
67
68
  return number[0..2] + "-" + number[3..6] if number.length == 7
68
69
  number
@@ -76,12 +77,15 @@ class String
76
77
  end
77
78
 
78
79
  def space2nbsp
79
- # turns double space to double nbsp
80
- (self.nil?)? "" : self.to_s.gsub(/ {2}/, "&nbsp;&nbsp;").html_safe
80
+ # turns >= double space to double nbsp
81
+ string = (self.nil?)? "" : self.to_s.gsub(/ {2,}/, "&nbsp;&nbsp;")
82
+ defined?(html_safe) ? string.html_safe : string
81
83
  end
82
84
 
85
+ # Replace the various combinations of newline characters with HTML <br> tags.
83
86
  def nl2br
84
- (self.nil?)? "" : self.to_s.gsub(/(\r)?\n/, "<br />").html_safe
87
+ string = (self.nil?)? "" : self.to_s.gsub(/(\r\n)|(\n\r)|\n|\v/, "<br>")
88
+ defined?(html_safe) ? string.html_safe : string
85
89
  end
86
90
 
87
91
 
data/lib/duffy/version.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  module Duffy
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.8'
3
3
  end
4
4
 
5
5
  # History
6
+ # 1.0.8 - Added support for +1 country code in pretty_phone.
7
+ # 1.0.7 - Added vertical tab to list of characters replace with <br> in nl2br.
6
8
  # 1.0.6 - Add to_markdown Array method.
7
9
  # 1.0.5 - Update smart_titlecase to better accommodate names.
8
10
  # 1.0.4 - Added battery_percent method.
data/spec/string_spec.rb CHANGED
@@ -8,11 +8,48 @@ 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"
14
47
  end
15
48
 
49
+ it "formats a +1 American phone number with Area Code" do
50
+ expect("+16081234567".pretty_phone).to eq "(608) 123-4567"
51
+ end
52
+
16
53
  it "formats an American phone number without Area Code" do
17
54
  expect("4567890".pretty_phone).to eq "456-7890"
18
55
  end
@@ -26,6 +63,21 @@ describe String do
26
63
  end
27
64
  end
28
65
 
66
+ describe "space2nbsp" do
67
+
68
+ it "leaves single space alone" do
69
+ expect("1 1".space2nbsp).to eq "1 1"
70
+ end
71
+
72
+ it "turns double space to double nbsp" do
73
+ expect("1 2".space2nbsp).to eq "1&nbsp;&nbsp;2"
74
+ end
75
+
76
+ it "turns triple space to double nbsp" do
77
+ expect("1 3".space2nbsp).to eq "1&nbsp;&nbsp;3"
78
+ end
79
+ end
80
+
29
81
  describe "smart_titlecase" do
30
82
  {
31
83
  "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.8
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: 2026-03-20 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