midwire_common 0.1.16 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/README.md +10 -4
- data/lib/midwire_common/string.rb +18 -45
- data/lib/midwire_common/version.rb +1 -1
- data/lib/tasks/version.rake +5 -8
- data/midwire_common.gemspec +2 -2
- data/spec/lib/midwire_common/string_spec.rb +25 -6
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e04bafc57480ef9e1be8a862de1884dbdb49e9
|
4
|
+
data.tar.gz: e9d8fdae68ba0a603013973be8ed0ba435fe47a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78c9f3ca123983e09bd591b41340eb101be591c6c5eb0b715a3ba36a49c65278af66f60dd3230cd3ce784233b688c3f0c2fc900c6a247e4055f7a0966c7a9786
|
7
|
+
data.tar.gz: 6b85526806618d3d4959790a879f69ba8854baa82056aa57111d5308b6bc52f6e1605ea96de78bdd3a0b645e5c634a32a2675b888607553ee04fef9e3cff1778
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
*0.1.17* (February 01, 2016)
|
2
|
+
|
3
|
+
* Fix some redundant self references in string.rb
|
4
|
+
* Simplify the email regex in string.rb
|
5
|
+
* Add 'snakerirze' and 'camelize' methods in string.rb
|
6
|
+
* Fix `version:bump` rake task to use single-quote string for VERSION.
|
7
|
+
* Remove 'pry' dependency for 'version.rake'
|
8
|
+
* Upgrade rubocop version
|
9
|
+
* Update the README.
|
10
|
+
* Add some specs to cover changes.
|
11
|
+
|
1
12
|
*0.1.16* (October 13, 2015)
|
2
13
|
|
3
14
|
* Add BottomlessHash
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Midwire Common Gem
|
2
2
|
|
3
|
-
**Version: 0.1.
|
3
|
+
**Version: 0.1.17**
|
4
4
|
|
5
|
-
A handy Ruby library for Midwire development
|
5
|
+
A handy, light-weight Ruby library for Midwire development
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
gem 'midwire_common'
|
11
|
+
gem 'midwire_common'
|
12
12
|
|
13
13
|
And then execute:
|
14
14
|
|
@@ -32,12 +32,18 @@ To use the standard class extensions you must include the individual files or 'm
|
|
32
32
|
To use the rake tasks simply `load` that rake file from within your main `Rakefile`:
|
33
33
|
|
34
34
|
begin
|
35
|
-
require
|
35
|
+
require 'midwire_common/rake_tasks'
|
36
36
|
rescue Exception => e
|
37
37
|
puts ">>> You have to run that under 'bundle exec'"
|
38
38
|
exit
|
39
39
|
end
|
40
40
|
|
41
|
+
Create a `CHANGELOG` file for your project.
|
42
|
+
|
43
|
+
touch CHANGELOG
|
44
|
+
|
45
|
+
The `rake version:*` tasks will prompt for CHANGELOG entries. Simply type them in and hit <CTRL>-d on a blank line when finished.
|
46
|
+
|
41
47
|
## Contributing
|
42
48
|
|
43
49
|
1. Fork it
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# A light-weight super String class
|
1
2
|
class String
|
2
3
|
class << self
|
3
4
|
def random(count = 6, ranges = [('a'..'z'), ('A'..'Z'), ('0'..'9')])
|
@@ -20,7 +21,7 @@ class String
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def left_trim!
|
23
|
-
|
24
|
+
gsub!(/^[\t\s]+/, '') || ''
|
24
25
|
end
|
25
26
|
|
26
27
|
def right_trim
|
@@ -29,7 +30,7 @@ class String
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def right_trim!
|
32
|
-
|
33
|
+
gsub!(/[\t\s]+$/, '') || ''
|
33
34
|
end
|
34
35
|
|
35
36
|
def trim
|
@@ -39,7 +40,7 @@ class String
|
|
39
40
|
|
40
41
|
def trim!
|
41
42
|
# remove leading and trailing whitespace
|
42
|
-
|
43
|
+
left_trim!.right_trim! || ''
|
43
44
|
end
|
44
45
|
|
45
46
|
# html = <<-stop.here_with_pipe(delimeter="\n")
|
@@ -58,51 +59,11 @@ class String
|
|
58
59
|
(self =~ regex) == 0 ? true : false
|
59
60
|
end
|
60
61
|
|
61
|
-
# rubocop:disable Metrics/LineLength
|
62
62
|
def email_address?
|
63
|
-
|
64
|
-
# //Use this version to seek out email addresses in random documents and texts.
|
65
|
-
# //Does not match email addresses using an IP address instead of a domain name.
|
66
|
-
# //Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
|
67
|
-
# //Including these increases the risk of false positives when applying the regex to random documents.
|
68
|
-
# '\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'
|
69
|
-
#
|
70
|
-
# //Email address (anchored)
|
71
|
-
# //Use this anchored version to check if a valid email address was entered.
|
72
|
-
# //Does not match email addresses using an IP address instead of a domain name.
|
73
|
-
# //Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
|
74
|
-
# //Requires the "case insensitive" option to be ON.
|
75
|
-
# '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$'
|
76
|
-
#
|
77
|
-
# //Email address (anchored; no consecutive dots)
|
78
|
-
# //Use this anchored version to check if a valid email address was entered.
|
79
|
-
# //Improves on the original email address regex by excluding addresses with consecutive dots such as john@aol...com
|
80
|
-
# //Does not match email addresses using an IP address instead of a domain name.
|
81
|
-
# //Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
|
82
|
-
# //Including these increases the risk of false positives when applying the regex to random documents.
|
83
|
-
# '^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$'
|
84
|
-
#
|
85
|
-
# //Email address (no consecutive dots)
|
86
|
-
# //Use this version to seek out email addresses in random documents and texts.
|
87
|
-
# //Improves on the original email address regex by excluding addresses with consecutive dots such as john@aol...com
|
88
|
-
# //Does not match email addresses using an IP address instead of a domain name.
|
89
|
-
# //Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum.
|
90
|
-
# //Including these increases the risk of false positives when applying the regex to random documents.
|
91
|
-
# '\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b'
|
92
|
-
#
|
93
|
-
# //Email address (specific TLDs)
|
94
|
-
# //Does not match email addresses using an IP address instead of a domain name.
|
95
|
-
# //Matches all country code top level domains, and specific common top level domains.
|
96
|
-
# '^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$'
|
97
|
-
#
|
98
|
-
# //Email address: Replace with HTML link
|
99
|
-
# '\b(?:mailto:)?([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b'
|
100
|
-
|
101
|
-
email_regex = %r{^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|jobs|museum|edu|pro)$}xi # Case insensitive
|
63
|
+
email_regex = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
|
102
64
|
|
103
65
|
(self =~ email_regex) == 0 ? true : false
|
104
66
|
end
|
105
|
-
# rubocop:enable Metrics/LineLength
|
106
67
|
|
107
68
|
def zipcode?
|
108
69
|
self =~ %r{^(\d{5})(-\d{4})?$}x ? true : false
|
@@ -126,7 +87,7 @@ class String
|
|
126
87
|
end
|
127
88
|
|
128
89
|
def sanitize!
|
129
|
-
|
90
|
+
gsub!(/[^a-z0-9,! \-\(\)\:\;\.\&\$]+/i, '')
|
130
91
|
end
|
131
92
|
|
132
93
|
def shorten(maxcount = 30)
|
@@ -151,4 +112,16 @@ class String
|
|
151
112
|
def escape_double_quotes
|
152
113
|
gsub(/["]/, '\\\\\"')
|
153
114
|
end
|
115
|
+
|
116
|
+
def snakerize
|
117
|
+
gsub(/::/, '/')
|
118
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
119
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
120
|
+
.tr('-', '_')
|
121
|
+
.downcase
|
122
|
+
end
|
123
|
+
|
124
|
+
def camelize
|
125
|
+
gsub(/\/(.?)/) { '::' + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
126
|
+
end
|
154
127
|
end
|
data/lib/tasks/version.rake
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'readline'
|
4
4
|
require 'fileutils'
|
5
|
-
require 'pry'
|
6
5
|
require 'midwire_common/string'
|
7
6
|
|
8
7
|
module Bundler
|
@@ -47,10 +46,8 @@ namespace :version do
|
|
47
46
|
Rake::Task['version:changes'].invoke
|
48
47
|
end
|
49
48
|
|
50
|
-
# rubocop:disable Style/Blocks
|
51
49
|
desc 'Alias for :bump_patch'
|
52
50
|
task bump: :bump_patch do; end
|
53
|
-
# rubocop:enable Style/Blocks
|
54
51
|
|
55
52
|
desc 'Increment the minor version and write changes to the changelog'
|
56
53
|
task :bump_minor do
|
@@ -81,9 +78,9 @@ namespace :version do
|
|
81
78
|
end
|
82
79
|
|
83
80
|
def module_name
|
84
|
-
if PROJECT_NAME
|
81
|
+
if PROJECT_NAME =~ /-/
|
85
82
|
PROJECT_NAME.split('-').map(&:capitalize).join('::')
|
86
|
-
elsif PROJECT_NAME
|
83
|
+
elsif PROJECT_NAME =~ /_/
|
87
84
|
PROJECT_NAME.split('_').map(&:capitalize).join
|
88
85
|
else
|
89
86
|
PROJECT_NAME.capitalize
|
@@ -98,7 +95,7 @@ namespace :version do
|
|
98
95
|
|
99
96
|
def write_version(version_array)
|
100
97
|
version = version_array.join('.')
|
101
|
-
new_version = %(VERSION =
|
98
|
+
new_version = %( VERSION = '#{version}')
|
102
99
|
lines = File.readlines(version_file_path)
|
103
100
|
File.open(version_file_path, 'w') do |f|
|
104
101
|
lines.each do |line|
|
@@ -115,7 +112,7 @@ namespace :version do
|
|
115
112
|
# read current changelog
|
116
113
|
old = File.read("#{PROJECT_ROOT}/CHANGELOG").to_s.chomp
|
117
114
|
text_array.push(old)
|
118
|
-
File.open("#{PROJECT_ROOT}/CHANGELOG", 'w')
|
115
|
+
File.open("#{PROJECT_ROOT}/CHANGELOG", 'w') do |f|
|
119
116
|
text_array.flatten.each do |line|
|
120
117
|
f.puts(line)
|
121
118
|
end
|
@@ -158,7 +155,7 @@ namespace :version do
|
|
158
155
|
return true unless current_branch == 'master'
|
159
156
|
puts(branch_warning_message)
|
160
157
|
while (line = $stdin.gets.chomp)
|
161
|
-
return true if line
|
158
|
+
return true if line =~ /[yY]/
|
162
159
|
puts 'Aborting version bump.'
|
163
160
|
return false
|
164
161
|
end
|
data/midwire_common.gemspec
CHANGED
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency 'guard-bundler', '~> 2.1'
|
22
22
|
spec.add_development_dependency 'guard-rspec', '~> 4.5'
|
23
23
|
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
24
|
-
spec.add_development_dependency 'pry', '~> 0.
|
24
|
+
spec.add_development_dependency 'pry-nav', '~> 0.2'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.1'
|
26
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.36'
|
27
27
|
|
28
28
|
spec.add_dependency 'thor', '~> 0.19'
|
29
29
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# rubocop:disable Metrics/LineLength
|
4
4
|
require 'spec_helper'
|
5
5
|
|
6
|
-
describe String do
|
6
|
+
RSpec.describe String do
|
7
7
|
it 'is a String' do
|
8
|
-
|
8
|
+
''.should be_a String
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'generates a random string' do
|
@@ -61,7 +61,7 @@ describe String do
|
|
61
61
|
|<script type="text/javascript">
|
62
62
|
|</script>
|
63
63
|
STOP
|
64
|
-
html.should ==
|
64
|
+
html.should == '<!-- Begin: comment --> <script type="text/javascript"> </script>'
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'here_with_pipe - with linefeeds' do
|
@@ -79,7 +79,7 @@ describe String do
|
|
79
79
|
|<script type="text/javascript">
|
80
80
|
|</script>
|
81
81
|
STOP
|
82
|
-
html.should ==
|
82
|
+
html.should == '<!-- Begin: comment --><script type="text/javascript"></script>'
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'format_phone returns a formatted phone number string' do
|
@@ -124,7 +124,7 @@ describe String do
|
|
124
124
|
|
125
125
|
it 'escapes double quotes' do
|
126
126
|
expect('this is a "test"'.escape_double_quotes)
|
127
|
-
.to eq(
|
127
|
+
.to eq('this is a \\\\"test\\\\"')
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
@@ -141,7 +141,6 @@ describe String do
|
|
141
141
|
it 'knows if it is an email address or not' do
|
142
142
|
'abcd_9191'.email_address?.should eq(false)
|
143
143
|
'abcd@9191'.email_address?.should eq(false)
|
144
|
-
'abcd@9191.poop'.email_address?.should eq(false)
|
145
144
|
'abcd@9191.info'.email_address?.should eq(true)
|
146
145
|
'abcd-asdf@9191.com'.email_address?.should eq(true)
|
147
146
|
'abcd_asdf@9191.com'.email_address?.should eq(true)
|
@@ -170,5 +169,25 @@ describe String do
|
|
170
169
|
' 12341. '.numeric?.should eq(false)
|
171
170
|
end
|
172
171
|
end
|
172
|
+
|
173
|
+
context '.snakerize' do
|
174
|
+
it 'changes CamelCased string to snake_cased' do
|
175
|
+
expect('CamelCased'.snakerize).to eq('camel_cased')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'handles doulbe-colon' do
|
179
|
+
expect('Camel::CasedTwo'.snakerize).to eq('camel/cased_two')
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context '.camelize' do
|
184
|
+
it 'changes snake cased string to camelized' do
|
185
|
+
expect('camel_cased'.camelize).to eq('CamelCased')
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'handles slash' do
|
189
|
+
expect('camel/cased_two'.camelize).to eq('Camel::CasedTwo')
|
190
|
+
end
|
191
|
+
end
|
173
192
|
end
|
174
193
|
# rubocop:enable Metrics/LineLength
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwire_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -95,19 +95,19 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
98
|
+
name: pry-nav
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.2'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.2'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0.
|
131
|
+
version: '0.36'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0.
|
138
|
+
version: '0.36'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: thor
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|