fat_core 3.0.0 → 4.0.0

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.
@@ -2,20 +2,44 @@ require 'fat_core/string'
2
2
 
3
3
  module FatCore
4
4
  module Symbol
5
- # Convert to capitalized string: :hello_world -> "Hello World"
6
- def entitle
5
+ # Convert to a title-ized string, that is, convert all '_' to a space, then
6
+ # call String#entitle on the result.
7
+ #
8
+ # @example
9
+ # :hello_world.entitle #=> "Hello World"
10
+ # :hello_world.as_string #=> "Hello World"
11
+ # :joy_to_the_world #=> 'Joy to the World'
12
+ #
13
+ # @return [String]
14
+ def as_string
7
15
  to_s.tr('_', ' ').split(' ').join(' ').entitle
8
16
  end
9
- alias as_string entitle
17
+ alias entitle as_string
10
18
 
19
+ # Return self. This (together with String#as_sym) allows `#as_sym` to be
20
+ # applied to a string or Symbol and get back a Symbol with out testing for
21
+ # type.
22
+ #
23
+ # @return [Symbol] just self
11
24
  def as_sym
12
25
  self
13
26
  end
14
27
 
28
+ # Prepare this symbol for use in a TeX document by converting to String then
29
+ # quoting it.
30
+ #
31
+ # @example
32
+ # :hammer_smith.tex_quote #=> "hammer\\_smith"
33
+ #
34
+ # @return [String]
15
35
  def tex_quote
16
36
  to_s.tex_quote
17
37
  end
18
38
  end
19
39
  end
20
40
 
21
- Symbol.include(FatCore::Symbol)
41
+ class Symbol
42
+ include FatCore::Symbol
43
+ # @!parse include FatCore::Symbol
44
+ # @!parse extend FatCore::Symbol::ClassMethods
45
+ end
@@ -1,7 +1,8 @@
1
1
  module FatCore
2
- MAJOR = 3
2
+ MAJOR = 4
3
3
  MINOR = 0
4
4
  PATCH = 0
5
5
 
6
+ # FatCore version number
6
7
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
8
  end
@@ -1,4 +1,4 @@
1
- require 'fat_core/big_decimal'
1
+ require 'fat_core/bigdecimal'
2
2
 
3
3
  describe BigDecimal do
4
4
  it 'should provide a human-readable inspect for BigDecimal' do
@@ -593,7 +593,7 @@ describe Date do
593
593
  expect(Date.today.add_chunk(:quarter)).to eq(Date.parse('2012-10-18'))
594
594
  expect(Date.today.add_chunk(:bimonth)).to eq(Date.parse('2012-09-18'))
595
595
  expect(Date.today.add_chunk(:month)).to eq(Date.parse('2012-08-18'))
596
- expect(Date.today.add_chunk(:semimonth)).to eq(Date.parse('2012-08-02'))
596
+ expect(Date.today.add_chunk(:semimonth)).to eq(Date.parse('2012-08-03'))
597
597
  expect(Date.today.add_chunk(:biweek)).to eq(Date.parse('2012-08-01'))
598
598
  expect(Date.today.add_chunk(:week)).to eq(Date.parse('2012-07-25'))
599
599
  expect(Date.today.add_chunk(:day)).to eq(Date.parse('2012-07-19'))
@@ -38,7 +38,7 @@ describe Numeric do
38
38
 
39
39
  # if places is nil, use 4 places for numbers with a fractional
40
40
  # part and 0 places for numbers without
41
- expect(-123_456_789.0123456.commas).to eq '-123,456,789.0123'
41
+ expect(-123_456_789.0123456.commas).to eq '-123,456,789.0123456'
42
42
  expect(-123_456_789.0.commas).to eq '-123,456,789'
43
43
  expect(-123_456_789.00.commas).to eq '-123,456,789'
44
44
  end
@@ -164,23 +164,25 @@ describe Range do
164
164
  end
165
165
 
166
166
  it 'should be able to determine whether a set contains covered overlaps' do
167
- expect((0..10)).to have_overlaps_within([(0..3), (2..6), (7..10)])
167
+ expect(Range.overlaps_among?([(0..3), (2..6), (7..10)])).to be true
168
+ expect((0..10).overlaps_among?([(0..3), (2..6), (7..10)])).to be true
168
169
  end
169
170
 
170
- it 'should not care about overlaps outside range' do
171
- expect((11..15)).to_not have_overlaps_within([(0..3), (2..6), (7..10)])
171
+ it 'should not care about overlaps outside self' do
172
+ expect(Range.overlaps_among?([(0..3), (2..6), (7..10)])).to be true
173
+ expect((11..15).overlaps_among?([(0..3), (2..6), (7..10)])).to be false
172
174
  end
173
175
 
174
176
  it 'should not count contiguous ranges as overlapping' do
175
- expect((0..10)).to_not have_overlaps_within([(0..3), (4..6), (7..10)])
177
+ expect(Range.overlaps_among?([(0..3), (4..6), (7..10)])).to be false
176
178
  end
177
179
 
178
180
  it 'should not count non-contiguous ranges as overlapping' do
179
- expect((0..10)).to_not have_overlaps_within([(0..3), (4..6), (8..10)])
181
+ expect(Range.overlaps_among?([(0..3), (4..6), (8..10)])).to be false
180
182
  end
181
183
 
182
184
  it 'should not count an empty set as overlapping' do
183
- expect((0..10)).to_not have_overlaps_within([])
185
+ expect(Range.overlaps_among?([])).to be false
184
186
  end
185
187
  end
186
188
 
@@ -1,4 +1,5 @@
1
1
  require 'fat_core/string'
2
+ require 'fat_core/date'
2
3
 
3
4
  describe String do
4
5
  before do
@@ -70,8 +71,20 @@ the people, for the people, shall not perish from the earth."
70
71
  expect(' string here '.clean).to eq 'string here'
71
72
  end
72
73
 
73
- it 'should be able to convert a digital date to iso form' do
74
- expect('20140521'.digdate2iso).to eq '2014-05-21'
74
+ it 'should be able to convert a numeric string to a commified form' do
75
+ expect('20140521'.commas).to eq '20,140,521'
76
+ expect('20140521.556'.commas).to eq '20,140,521.556'
77
+ expect('20140521.556'.commas(2)).to eq '20,140,521.56'
78
+ expect('-20140521.556'.commas).to eq '-20,140,521.556'
79
+ expect('+20140521.556'.commas).to eq '20,140,521.556'
80
+ expect('+20140521.556e3'.commas).to eq '20,140,521,556'
81
+ end
82
+
83
+ it 'should be able to convert a digital date to a Date' do
84
+ expect('20140521'.as_date.iso).to eq '2014-05-21'
85
+ expect('2014-05-21'.as_date.iso).to eq '2014-05-21'
86
+ expect('2014/05/21'.as_date.iso).to eq '2014-05-21'
87
+ expect('2014/5/21'.as_date.iso).to eq '2014-05-21'
75
88
  end
76
89
 
77
90
  it 'should wrap a short string' do
@@ -97,13 +110,6 @@ the people, for the people, shall not perish from the earth."
97
110
  expect(str.split("\n")[23]).to match(/^#{twenty_fourth_line}/)
98
111
  end
99
112
 
100
- it 'should be able to quote special TeX characters' do
101
- expect('$10,000'.tex_quote).to eq('\\$10,000')
102
- expect('would~~have'.tex_quote).to eq('would\\textasciitilde{}\\textasciitilde{}have')
103
- expect('<hello>'.tex_quote).to eq('\\textless{}hello\\textgreater{}')
104
- expect('{hello}'.tex_quote).to eq('\\{hello\\}')
105
- end
106
-
107
113
  it 'should be able to determine is it\'s a valid number' do
108
114
  expect('88'.number?).to be true
109
115
  expect('-88'.number?).to be true
@@ -147,44 +153,6 @@ the people, for the people, shall not perish from the earth."
147
153
  .to eq "hello world it's me"
148
154
  end
149
155
 
150
- it 'should be able to fuzzy match with another string' do
151
- expect('Hello, world'.fuzzy_match('or')).to be_truthy
152
- expect('Hello, world'.fuzzy_match('ox')).to be_falsy
153
- end
154
-
155
- it 'should be able to match with another string containing re' do
156
- expect('Hello, world'.matches_with('/or/')).to be_truthy
157
- expect('Hello, world'.matches_with('/ox/')).to be_falsy
158
- end
159
-
160
- it 'should be able to match with another string containing string' do
161
- expect('Hello, world'.matches_with('or')).to be_truthy
162
- expect('Hello, world'.matches_with('ox')).to be_falsy
163
- end
164
-
165
- it 'should be able to fuzzy match space-separated parts' do
166
- expect('Hello world'.fuzzy_match('hel or')).to be_truthy
167
- expect('Hello, world'.fuzzy_match('hel ox')).to be_falsy
168
- end
169
-
170
- it 'should be able to fuzzy match colon-separated parts' do
171
- expect('Hello:world'.fuzzy_match('hel:or')).to be_truthy
172
- expect('Hello:world'.fuzzy_match('hel:ox')).to be_falsy
173
- end
174
-
175
- it 'should return the matched text' do
176
- expect('Hello:world'.fuzzy_match('hel')).to eq('Hel')
177
- expect('Hello:world'.fuzzy_match('hel:or')).to eq('Hello:wor')
178
- expect('Hello:world'.matches_with('/^h.*r/')).to eq('Hello:wor')
179
- end
180
-
181
- it 'should ignore periods, commas, and apostrophes when matching' do
182
- expect("St. Luke's".fuzzy_match('st lukes')).to eq('St Lukes')
183
- expect('St Lukes'.fuzzy_match('st. luke\'s')).to eq('St Lukes')
184
- expect('St Lukes, Inc.'.fuzzy_match('st luke inc')).to eq('St Lukes Inc')
185
- expect('E*TRADE'.fuzzy_match('etrade')).to eq('ETRADE')
186
- end
187
-
188
156
  it 'should be able to properly capitalize a string as a title' do
189
157
  # Capitalize little words only at beginning and end
190
158
  expect('the cat in the hat'.entitle).to eq('The Cat in the Hat')
@@ -194,14 +162,14 @@ the people, for the people, shall not perish from the earth."
194
162
  expect('tr'.entitle).to eq('Tr')
195
163
  expect('trd'.entitle).to eq('TRD')
196
164
  # Don't capitalize c/o
197
- expect('IBM c/o watson'.entitle).to eq('Ibm c/o Watson')
165
+ expect('IBM c/o watson'.entitle).to eq('IBM c/o Watson')
198
166
  # Capitlaize p.o.
199
167
  expect('p.o. box 123'.entitle).to eq('P.O. Box 123')
200
168
  # Don't capitalize ordinals
201
169
  expect('22nd of september'.entitle).to eq('22nd of September')
202
170
  # Capitalize common abbrevs
203
- expect('US BANK'.entitle).to eq('US Bank')
204
- expect('NW territory'.entitle).to eq('NW Territory')
171
+ expect('US BANK'.entitle).to eq('US BANK')
172
+ expect('nw territory'.entitle).to eq('NW Territory')
205
173
  # Leave word starting with numbers alone
206
174
  expect('apartment 33-B'.entitle).to eq('Apartment 33-B')
207
175
  # Assume all consanants is an acronym
@@ -212,14 +180,60 @@ the people, for the people, shall not perish from the earth."
212
180
 
213
181
  it 'should be able to compute its Levenshtein distance from another string' do
214
182
  expect('Something'.distance('Smoething')).to eq 1
215
- expect('Something'.distance('Smoething', block_size: 0)).to eq 2
216
- expect('Something'.distance('meSothing', block_size: 1)).to eq 4
217
- expect('Something'.distance('meSothing', block_size: 2)).to eq 2
218
- expect('SomethingElse'.distance('Encyclopedia')).to eq 10
219
- expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica', max_distance: 40))
220
- .to eq 21
221
- expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica',
222
- max_distance: 15)).to eq 15
183
+ expect('Something'.distance('meSothing')).to eq 4
184
+ expect('SomethingElse'.distance('Encyclopedia')).to eq 11
185
+ expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica'))
186
+ .to eq 11
187
+ expect('SomethingElseUnrelated'.distance('EncyclopediaBritanica')).to eq 11
188
+ end
189
+
190
+ describe 'Quoting' do
191
+ it 'should be able to quote special TeX characters' do
192
+ expect('$10,000'.tex_quote).to eq('\\$10,000')
193
+ expect('would~~have'.tex_quote).to eq('would\\textasciitilde{}\\textasciitilde{}have')
194
+ expect('<hello>'.tex_quote).to eq('\\textless{}hello\\textgreater{}')
195
+ expect('{hello}'.tex_quote).to eq('\\{hello\\}')
196
+ end
197
+ end
198
+
199
+ describe 'Matching' do
200
+ it 'should be able to fuzzy match with another string' do
201
+ expect('Hello, world'.fuzzy_match('or')).to be_truthy
202
+ expect('Hello, world'.fuzzy_match('ox')).to be_falsy
203
+ end
204
+
205
+ it 'should be able to fuzzy match with another string containing re' do
206
+ expect('Hello, world'.matches_with('/or/')).to be_truthy
207
+ expect('Hello, world'.matches_with('/ox/')).to be_falsy
208
+ end
209
+
210
+ it 'should be able to fuzzy match space-separated parts' do
211
+ expect('Hello world'.fuzzy_match('hel or')).to be_truthy
212
+ expect('Hello, world'.fuzzy_match('hel ox')).to be_falsy
213
+ end
214
+
215
+ it 'should be able to fuzzy match colon-separated parts' do
216
+ expect('Hello:world'.fuzzy_match('hel:or')).to be_truthy
217
+ expect('Hello:world'.fuzzy_match('hel:ox')).to be_falsy
218
+ end
219
+
220
+ it 'should be able to fuzzy match colon-separated parts' do
221
+ expect('Hello:world'.fuzzy_match('hel:or')).to be_truthy
222
+ expect('Hello:world'.fuzzy_match('hel:ox')).to be_falsy
223
+ end
224
+
225
+ it 'should return the matched text' do
226
+ expect('Hello:world'.fuzzy_match('hel')).to eq('Hel')
227
+ expect('Hello:world'.fuzzy_match('hel:or')).to eq('Hello:wor')
228
+ expect('Hello:world'.matches_with('/^h.*r/')).to eq('Hello:wor')
229
+ end
230
+
231
+ it 'should ignore periods, commas, and apostrophes when matching' do
232
+ expect("St. Luke's".fuzzy_match('st lukes')).to eq('St Lukes')
233
+ expect('St Lukes'.fuzzy_match('st. luke\'s')).to eq('St Lukes')
234
+ expect('St Lukes, Inc.'.fuzzy_match('st luke inc')).to eq('St Lukes Inc')
235
+ expect('E*TRADE'.fuzzy_match('etrade')).to eq('ETRADE')
236
+ end
223
237
  end
224
238
  end
225
239
  end
data/spec/spec_helper.rb CHANGED
@@ -5,8 +5,9 @@ SimpleCov.start
5
5
  require 'bundler/setup'
6
6
  Bundler.setup
7
7
 
8
- require 'pry'
9
- require 'byebug'
8
+ # Note: I now include these in my global ~/.rspec file, so no need for them
9
+ # here.
10
+ # require 'pry' require 'byebug'
10
11
 
11
12
  # This file was generated by the `rspec --init` command. Conventionally, all
12
13
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fat_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-09 00:00:00.000000000 Z
11
+ date: 2017-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rcodetools
126
+ name: redcarpet
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -182,7 +182,6 @@ description: Write a longer description. Optional.
182
182
  email:
183
183
  - ded@ddoherty.net
184
184
  executables:
185
- - console
186
185
  - easters
187
186
  extensions: []
188
187
  extra_rdoc_files: []
@@ -201,12 +200,11 @@ files:
201
200
  - bin/console
202
201
  - bin/easters
203
202
  - fat_core.gemspec
204
- - lib/core_extensions/date/fat_core.rb
205
203
  - lib/fat_core.rb
206
204
  - lib/fat_core/ChangeLog
207
205
  - lib/fat_core/all.rb
208
206
  - lib/fat_core/array.rb
209
- - lib/fat_core/big_decimal.rb
207
+ - lib/fat_core/bigdecimal.rb
210
208
  - lib/fat_core/date.rb
211
209
  - lib/fat_core/enumerable.rb
212
210
  - lib/fat_core/hash.rb
@@ -218,7 +216,7 @@ files:
218
216
  - lib/fat_core/symbol.rb
219
217
  - lib/fat_core/version.rb
220
218
  - spec/lib/array_spec.rb
221
- - spec/lib/big_decimal_spec.rb
219
+ - spec/lib/bigdecimal_spec.rb
222
220
  - spec/lib/date_spec.rb
223
221
  - spec/lib/enumerable_spec.rb
224
222
  - spec/lib/hash_spec.rb
@@ -232,7 +230,8 @@ files:
232
230
  homepage: ''
233
231
  licenses:
234
232
  - MIT
235
- metadata: {}
233
+ metadata:
234
+ yard.run: yri
236
235
  post_install_message:
237
236
  rdoc_options: []
238
237
  require_paths:
@@ -249,13 +248,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
248
  version: '0'
250
249
  requirements: []
251
250
  rubyforge_project:
252
- rubygems_version: 2.5.1
251
+ rubygems_version: 2.5.2
253
252
  signing_key:
254
253
  specification_version: 4
255
254
  summary: fat_core provides some useful core extensions
256
255
  test_files:
257
256
  - spec/lib/array_spec.rb
258
- - spec/lib/big_decimal_spec.rb
257
+ - spec/lib/bigdecimal_spec.rb
259
258
  - spec/lib/date_spec.rb
260
259
  - spec/lib/enumerable_spec.rb
261
260
  - spec/lib/hash_spec.rb
@@ -1,6 +0,0 @@
1
- module CoreExtensions
2
- module Date
3
- module FatCore
4
- end
5
- end
6
- end
@@ -1,12 +0,0 @@
1
- require 'bigdecimal'
2
-
3
- module FatCore
4
- module BigDecimal
5
- # Provide a human-readable display for BigDecimal. e.g., while debugging.
6
- def inspect
7
- to_f.to_s
8
- end
9
- end
10
- end
11
-
12
- BigDecimal.prepend(FatCore::BigDecimal)