finishing_moves 0.13 → 0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e83beb44f31e133f35900b3e4b2dd3c6a0bb1b7
4
- data.tar.gz: 3f1d6578baff446873c089be7103a72cc9c66d5a
3
+ metadata.gz: 7a718608d670ad9c35de37ea5dd0b771940fd44f
4
+ data.tar.gz: 51ee2d5e25c1b1e4aa39b54514b72957cf6e057f
5
5
  SHA512:
6
- metadata.gz: 36212ac6505a5705703b4855e50ed524e820df417d9e082b1696eb7c2b4be4860b76c5e4d18197fd115a49bafc884964cbf22cf4c4373347a1ad0d3fad369080
7
- data.tar.gz: 2eb008c733f17451d67cb91f5433ce864ffe29c4e53f00a5aa385ef630979b6f2d03722fa4a8f04f6d4ec442b35625c5db33437ce247a037abdb7f531a1e9226
6
+ metadata.gz: 5e944094a9386678dd096ac6bce7c09efcc05b24cabbbd33723d67755a0db13d534573fd1d63ca4f5f1993bf6eb5289c8eb79b8578b1fcc03241fef192c7b1e8
7
+ data.tar.gz: 8ed9d4e5e54277a26d9e5b84fcc3c319107408814308e17d413fe7de25a7282ddb3996b92d062db1242501c9d79b5b731b5033a653a3f88836117005e5b5feb3
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.email = ["frank@forgecrafted.com", "chris@forgecrafted.com"]
12
12
  s.summary = %q{Small, focused, incredibly useful methods added to core Ruby classes.}
13
13
  s.description = <<-EOF
14
- Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself in a situation where an elaborate-yet-precise coding maneuver wins the day. Finishing Moves is a collection of methods designed to assist in those just-typical-enough-to-be-annoying scenarios.
14
+ Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself performing contortions to achieve results that, honestly, should feel more natural given the language's design elegance. Finishing Moves is a collection of methods designed to assist in those "why is this awkward?" scenarios.
15
15
  EOF
16
16
  s.homepage = "https://github.com/forgecrafted/finishing_moves"
17
17
  s.license = "MIT"
@@ -24,4 +24,9 @@ class Hash
24
24
  return self
25
25
  end
26
26
 
27
+ # TODO
28
+ # return copy of hash with all key:value pairs except those listed in args
29
+ def except(*keys)
30
+ end
31
+
27
32
  end
@@ -1,7 +1,11 @@
1
1
  class String
2
2
 
3
3
  def nl2br
4
- self.gsub(/(?:\n\r?|\r\n?)/, "<br />\n")
4
+ _nl_gsub("<br />\n")
5
+ end
6
+
7
+ def newline_to(rep = ' ')
8
+ _nl_gsub(rep.to_s)
5
9
  end
6
10
 
7
11
  def keyify
@@ -65,11 +69,19 @@ class String
65
69
  str.each_char { |c| gsub! /#{Regexp.escape c}{2,}/, c }
66
70
  end
67
71
 
68
- def remove_whitespace(replace = '')
72
+ def remove_whitespace(_ignored = nil)
73
+ replace_whitespace('')
74
+ end
75
+
76
+ def remove_whitespace!(_ignored = nil)
77
+ replace_whitespace!('')
78
+ end
79
+
80
+ def replace_whitespace(replace = '')
69
81
  gsub /[ ]/, replace
70
82
  end
71
83
 
72
- def remove_whitespace!(replace = '')
84
+ def replace_whitespace!(replace = '')
73
85
  gsub! /[ ]/, replace
74
86
  end
75
87
 
@@ -86,8 +98,18 @@ class String
86
98
  Float(self) != nil rescue false
87
99
  end
88
100
 
101
+ # TODO
102
+ def each_char_index(&block)
103
+ # how to return enumerator if no block given?
104
+ # http://blog.arkency.com/2014/01/ruby-to-enum-for-enumerator/
105
+ end
106
+
89
107
  protected
90
108
 
109
+ def _nl_gsub(rep)
110
+ self.gsub(/(?:\n\r?|\r\n?)/, rep)
111
+ end
112
+
91
113
  def _lstrip_all_regex(expr)
92
114
  /\A[#{expr}]+/
93
115
  end
@@ -1,3 +1,3 @@
1
1
  module FinishingMoves
2
- VERSION = "0.13"
2
+ VERSION = "0.14"
3
3
  end
data/spec/string_spec.rb CHANGED
@@ -99,9 +99,9 @@ describe String do
99
99
  expect(' [ foo ] '.remove_whitespace).to eq '[foo]'
100
100
  expect(' '.remove_whitespace).to eq ''
101
101
  expect('. $ ^ { [ ( | ) * + ? \ '.remove_whitespace).to eq '.$^{[(|)*+?\\'
102
- expect('a b c d e'.remove_whitespace('+')).to eq 'a+b+c+d+e'
103
- expect('a b c d e'.remove_whitespace('+')).to eq 'a++b+c+d+e'
104
- expect('a b c d e'.remove_whitespace('__')).to eq 'a__b__c__d__e'
102
+ expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
103
+ expect('a b c d e'.remove_whitespace('+')).to eq 'abcde'
104
+ expect('a b c d e'.remove_whitespace('__')).to eq 'abcde'
105
105
  end
106
106
 
107
107
  it '#remove_whitespace!' do
@@ -110,6 +110,19 @@ describe String do
110
110
  expect(str).to eq 'abcde'
111
111
  end
112
112
 
113
+ it '#replace_whitespace' do
114
+ expect(' a b c d e'.replace_whitespace).to eq 'abcde'
115
+ expect('a b c d e'.replace_whitespace('+')).to eq 'a+b+c+d+e'
116
+ expect('a b c d e'.replace_whitespace('+')).to eq 'a++b+c+d+e'
117
+ expect('a b c d e'.replace_whitespace('__')).to eq 'a__b__c__d__e'
118
+ end
119
+
120
+ it '#replace_whitespace!' do
121
+ str = 'a b c d e'
122
+ str.replace_whitespace!('-')
123
+ expect(str).to eq 'a-b-c-d-e'
124
+ end
125
+
113
126
  it '#nl2br' do
114
127
  expect("\n".nl2br).to eq "<br />\n"
115
128
  expect("\n\r".nl2br).to eq "<br />\n"
@@ -125,6 +138,27 @@ describe String do
125
138
  to eq "A strange game.<br />\n<br />\nThe only winning move is not to play.<br />\nHow about a nice game of chess?<br />\n"
126
139
  end
127
140
 
141
+ it "#newline_to" do
142
+ expect("\n".newline_to).to eq " "
143
+ expect("\n\r".newline_to).to eq " "
144
+ expect("\r\n".newline_to).to eq " "
145
+ expect("\n\r\n".newline_to).to eq " "
146
+ expect("\r\n\r\n".newline_to).to eq " "
147
+ expect("\r\r\n".newline_to).to eq " "
148
+ expect("\r\r".newline_to).to eq " "
149
+ expect("\n\r\r".newline_to).to eq " "
150
+
151
+ # replacements should end up as strings
152
+ expect("\n".newline_to(:bar)).to eq 'bar'
153
+ expect("\n\n".newline_to('+')).to eq '++'
154
+ expect("\n\n".newline_to(0)).to eq '00'
155
+ expect("\n\n".newline_to(true)).to eq 'truetrue'
156
+
157
+ expect("Let's play Global Thermonuclear War.\n\r".newline_to).to eq "Let's play Global Thermonuclear War. "
158
+ expect("A strange game.\n\nThe only winning move is not to play.\r\nHow about a nice game of chess?\r".newline_to).
159
+ to eq "A strange game. The only winning move is not to play. How about a nice game of chess? "
160
+ end
161
+
128
162
  it '#keyify' do
129
163
  expect(Integer.keyify).to eq :integer
130
164
  expect(Math::DomainError.keyify).to eq :math_domain_error
@@ -155,7 +189,8 @@ describe String do
155
189
  end
156
190
 
157
191
  it "dedupe + remove_whitespace" do
158
- expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '1+2+3+4+5'
192
+ expect('1 2 3 4 5'.dedupe(' ').remove_whitespace('+')).to eq '12345'
193
+ expect('1 2 3 4 5'.dedupe(' ').replace_whitespace('+')).to eq '1+2+3+4+5'
159
194
  end
160
195
 
161
196
  it '#slugify' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finishing_moves
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.13'
4
+ version: '0.14'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Koehl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-08 00:00:00.000000000 Z
12
+ date: 2017-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-readline
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: 0.8.0
98
98
  description: |2
99
- Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself in a situation where an elaborate-yet-precise coding maneuver wins the day. Finishing Moves is a collection of methods designed to assist in those just-typical-enough-to-be-annoying scenarios.
99
+ Ruby includes a huge amount of default awesomeness that tackles most common development challenges. But every now and then, you find yourself performing contortions to achieve results that, honestly, should feel more natural given the language's design elegance. Finishing Moves is a collection of methods designed to assist in those "why is this awkward?" scenarios.
100
100
  email:
101
101
  - frank@forgecrafted.com
102
102
  - chris@forgecrafted.com