fat_core 0.1.11 → 0.1.12
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 +4 -4
- data/lib/fat_core/hash.rb +1 -0
- data/lib/fat_core/numeric.rb +1 -1
- data/lib/fat_core/period.rb +15 -18
- data/lib/fat_core/string.rb +3 -2
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/array_spec.rb +8 -0
- data/spec/lib/date_spec.rb +14 -8
- data/spec/lib/enumerable_spec.rb +10 -0
- data/spec/lib/hash_spec.rb +24 -0
- data/spec/lib/nil_spec.rb +11 -0
- data/spec/lib/numeric_spec.rb +32 -0
- data/spec/lib/period_spec.rb +105 -2
- data/spec/lib/string_spec.rb +125 -58
- data/spec/lib/symbol_spec.rb +16 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffa9bd02f68ddfae5676b80fb9b9f6db788e66e6
|
4
|
+
data.tar.gz: b865e251c27c603fa9ea25698f64f644de508ba2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3994eda5e762e1a979f0c609320919f7d03e9fbdbb2dd441cfef1cf634f01e0d8b2c68f8603fc7456294dcb129feb32c79c07568c9f221cad9a86deb40e83783
|
7
|
+
data.tar.gz: f9d315906028ebcc769341b44f972e0f2f91f6577e83ae918a18d7618208066ebca3c8da9f3ea3b190a6ad416b3aff098e344c013039d4ce9407309949231870
|
data/lib/fat_core/hash.rb
CHANGED
data/lib/fat_core/numeric.rb
CHANGED
@@ -13,7 +13,7 @@ class Numeric
|
|
13
13
|
# By default, use zero places for whole numbers; four places for
|
14
14
|
# numbers containing a fractional part to 4 places.
|
15
15
|
if places.nil?
|
16
|
-
if self.modulo(1).round(4) > 0.0
|
16
|
+
if self.abs.modulo(1).round(4) > 0.0
|
17
17
|
places = 4
|
18
18
|
else
|
19
19
|
places = 0
|
data/lib/fat_core/period.rb
CHANGED
@@ -157,29 +157,34 @@ class Period
|
|
157
157
|
92
|
158
158
|
when :year
|
159
159
|
366
|
160
|
+
when :irregular
|
161
|
+
raise ArgumentError, "no maximum period for :irregular chunk"
|
160
162
|
else
|
161
163
|
chunk_sym_to_days(sym)
|
162
164
|
end
|
163
165
|
end
|
164
166
|
|
165
|
-
# This is only used for inferring statement frequency based on the
|
166
|
-
# of days between statements, so it will not consider all
|
167
|
-
# only :year, :quarter, :month, and :week. And
|
168
|
-
# :semimonth and :biweek is impossible
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
# so a "quarter" here is much broader than the calendar definition. Ditto
|
173
|
-
# for the others, but since statements are most likely monthly, we default
|
174
|
-
# to :month.
|
167
|
+
# This is only used for inferring statement frequency based on the
|
168
|
+
# number of days between statements, so it will not consider all
|
169
|
+
# possible chunks, only :year, :quarter, :month, and :week. And
|
170
|
+
# distinguishing between :semimonth and :biweek is impossible in
|
171
|
+
# some cases since a :semimonth can be 14 days just like a :biweek.
|
172
|
+
# This ignores that possiblity and requires a :semimonth to be at
|
173
|
+
# least 15 days.
|
175
174
|
def self.days_to_chunk_sym(days)
|
176
175
|
case days
|
177
176
|
when 356..376
|
178
177
|
:year
|
179
178
|
when 86..96
|
180
179
|
:quarter
|
180
|
+
when 59..62
|
181
|
+
:bimonth
|
181
182
|
when 26..33
|
182
183
|
:month
|
184
|
+
when 15..16
|
185
|
+
:semimonth
|
186
|
+
when 14
|
187
|
+
:biweek
|
183
188
|
when 7
|
184
189
|
:week
|
185
190
|
when 1
|
@@ -189,14 +194,6 @@ class Period
|
|
189
194
|
end
|
190
195
|
end
|
191
196
|
|
192
|
-
def size
|
193
|
-
to_range.size
|
194
|
-
end
|
195
|
-
|
196
|
-
def length
|
197
|
-
size
|
198
|
-
end
|
199
|
-
|
200
197
|
def to_range
|
201
198
|
(first..last)
|
202
199
|
end
|
data/lib/fat_core/string.rb
CHANGED
@@ -62,7 +62,8 @@ class String
|
|
62
62
|
|
63
63
|
# Convert to symbol "Hello World" -> :hello_world
|
64
64
|
def as_sym
|
65
|
-
strip.squeeze(' ').gsub(/\s+/, '_').
|
65
|
+
strip.squeeze(' ').gsub(/\s+/, '_').
|
66
|
+
gsub(/[^_A-Za-z]/, '').downcase.to_sym
|
66
67
|
end
|
67
68
|
|
68
69
|
def as_string
|
@@ -103,7 +104,7 @@ class String
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def self.random(size = 8)
|
106
|
-
|
107
|
+
('a'..'z').cycle.take(size).shuffle.join
|
107
108
|
end
|
108
109
|
|
109
110
|
# Convert a string with an all-digit date to an iso string
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/date_spec.rb
CHANGED
@@ -10,7 +10,6 @@ describe Date do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "class methods" do
|
13
|
-
|
14
13
|
describe "date arithmetic" do
|
15
14
|
it "should know the number of days in a month" do
|
16
15
|
expect(Date.days_in_month(2000, 1)).to eq 31
|
@@ -42,18 +41,25 @@ describe Date do
|
|
42
41
|
# 26 27 28 29 30 31
|
43
42
|
|
44
43
|
# First Monday
|
45
|
-
expect(Date.nth_wday_in_year_month(1, 1, 2014, 1))
|
44
|
+
expect(Date.nth_wday_in_year_month(1, 1, 2014, 1))
|
45
|
+
.to eq Date.parse('2014-01-06')
|
46
46
|
# Second Monday
|
47
|
-
expect(Date.nth_wday_in_year_month(2, 1, 2014, 1))
|
47
|
+
expect(Date.nth_wday_in_year_month(2, 1, 2014, 1))
|
48
|
+
.to eq Date.parse('2014-01-13')
|
48
49
|
# Third Sunday
|
49
|
-
expect(Date.nth_wday_in_year_month(3, 0, 2014, 1))
|
50
|
+
expect(Date.nth_wday_in_year_month(3, 0, 2014, 1))
|
51
|
+
.to eq Date.parse('2014-01-19')
|
50
52
|
# Third Sunday (float floored)
|
51
|
-
expect(Date.nth_wday_in_year_month(3.2, 0, 2014, 1))
|
53
|
+
expect(Date.nth_wday_in_year_month(3.2, 0, 2014, 1))
|
54
|
+
.to eq Date.parse('2014-01-19')
|
52
55
|
# Negative wday counts from end: Last Sunday
|
53
|
-
expect(Date.nth_wday_in_year_month(-1, 0, 2014, 1))
|
54
|
-
|
56
|
+
expect(Date.nth_wday_in_year_month(-1, 0, 2014, 1))
|
57
|
+
.to eq Date.parse('2014-01-26')
|
58
|
+
expect(Date.nth_wday_in_year_month(-3, 0, 2014, 1))
|
59
|
+
.to eq Date.parse('2014-01-12')
|
55
60
|
# Negative wday counts from end: Last Thursday
|
56
|
-
expect(Date.nth_wday_in_year_month(-1, 4, 2014, 1))
|
61
|
+
expect(Date.nth_wday_in_year_month(-1, 4, 2014, 1))
|
62
|
+
.to eq Date.parse('2014-01-30')
|
57
63
|
|
58
64
|
# Exceptions
|
59
65
|
expect {
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
it "should be able to find keys with a value == to X" do
|
5
|
+
hh = {:a => 1, :b => 2, :c => 1 }
|
6
|
+
expect(hh.keys_with_value(1)).to eq [:a, :c]
|
7
|
+
expect(hh.keys_with_value(9)).to eq []
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to delete entries with a value == to X" do
|
11
|
+
hh = {:a => 1, :b => 2, :c => 1 }
|
12
|
+
expect(hh.delete_with_value(1)).to eq({ :b => 2 })
|
13
|
+
expect(hh.delete_with_value(9)).to eq hh
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to map keys to new keys" do
|
17
|
+
hh = { :a => 1, :b => 2, :c => 1 }
|
18
|
+
remap = { :a => :d, :b => :e, :c => :f }
|
19
|
+
expect(hh.remap_keys(remap)).to eq({ :d => 1, :e => 2, :f => 1 })
|
20
|
+
|
21
|
+
remap = { :a => :d }
|
22
|
+
expect(hh.remap_keys(remap)).to eq({ :d => 1, :b => 2, :c => 1 })
|
23
|
+
end
|
24
|
+
end
|
data/spec/lib/numeric_spec.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
1
|
require File.dirname(File.absolute_path(__FILE__)) + '/../spec_helper.rb'
|
2
2
|
|
3
3
|
describe Numeric do
|
4
|
+
it "should implement signum function" do
|
5
|
+
# Integers
|
6
|
+
expect(33.signum).to eq 1
|
7
|
+
expect(-33.signum).to eq -1
|
8
|
+
expect(0.signum).to eq 0
|
9
|
+
|
10
|
+
# Floats
|
11
|
+
expect(33.45.signum).to eq 1
|
12
|
+
expect(-33.45.signum).to eq -1
|
13
|
+
expect(0.0.signum).to eq 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should provide a tex_quote method for erb docs" do
|
17
|
+
expect(195.45.tex_quote).to eq '195.45'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should provide a human-readable inspect for BigDecimal" do
|
21
|
+
expect(BigDecimal('33.45').inspect).to eq '33.45'
|
22
|
+
end
|
23
|
+
|
4
24
|
it "should properly round up" do
|
5
25
|
expect(236.5555.commas(2)).to eq '236.56'
|
6
26
|
expect(-236.5555.commas(2)).to eq '-236.56'
|
@@ -14,6 +34,18 @@ describe Numeric do
|
|
14
34
|
it "should place commas properly" do
|
15
35
|
expect(123456789.0123.commas(2)).to eq '123,456,789.01'
|
16
36
|
expect(-123456789.0123.commas(2)).to eq '-123,456,789.01'
|
37
|
+
|
38
|
+
# if places is nil, use 4 places for numbers with a fractional
|
39
|
+
# part and 0 places for numbers without
|
40
|
+
expect(-123456789.0123456.commas).to eq '-123,456,789.0123'
|
41
|
+
expect(-123456789.0.commas).to eq '-123,456,789'
|
42
|
+
expect(-123456789.00.commas).to eq '-123,456,789'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be able to convert a non-fractional float to an int" do
|
46
|
+
expect(195.45.int_if_whole).to eq 195.45
|
47
|
+
expect(195.0.int_if_whole).to eq 195
|
48
|
+
expect(195.0.int_if_whole.class).to eq Fixnum
|
17
49
|
end
|
18
50
|
|
19
51
|
it "should place commas properly with no fraction" do
|
data/spec/lib/period_spec.rb
CHANGED
@@ -50,6 +50,10 @@ describe Period do
|
|
50
50
|
expect(Period.parse_spec(nil, '2014-3Q').last).to eq Date.parse('2014-09-30')
|
51
51
|
end
|
52
52
|
|
53
|
+
it "should know what the valid chunk syms are" do
|
54
|
+
expect(Period.chunk_syms.size).to eq 9
|
55
|
+
end
|
56
|
+
|
53
57
|
it "should know the days in a chunk sym" do
|
54
58
|
expect(Period.chunk_sym_to_days(:year)).to eq(365)
|
55
59
|
expect(Period.chunk_sym_to_days(:quarter)).to eq(90)
|
@@ -65,6 +69,22 @@ describe Period do
|
|
65
69
|
}.to raise_error ArgumentError
|
66
70
|
end
|
67
71
|
|
72
|
+
it "should know the maximum days in a chunk sym" do
|
73
|
+
expect(Period.chunk_sym_to_max_days(:year)).to eq(366)
|
74
|
+
expect(Period.chunk_sym_to_max_days(:quarter)).to eq(92)
|
75
|
+
expect(Period.chunk_sym_to_max_days(:bimonth)).to eq(62)
|
76
|
+
expect(Period.chunk_sym_to_max_days(:month)).to eq(31)
|
77
|
+
expect(Period.chunk_sym_to_max_days(:semimonth)).to eq(16)
|
78
|
+
expect(Period.chunk_sym_to_max_days(:biweek)).to eq(14)
|
79
|
+
expect(Period.chunk_sym_to_max_days(:week)).to eq(7)
|
80
|
+
expect(Period.chunk_sym_to_max_days(:day)).to eq(1)
|
81
|
+
expect{ Period.chunk_sym_to_max_days(:irregular) }
|
82
|
+
.to raise_error ArgumentError
|
83
|
+
expect {
|
84
|
+
Period.chunk_sym_to_days(:eon)
|
85
|
+
}.to raise_error ArgumentError
|
86
|
+
end
|
87
|
+
|
68
88
|
it "should know the chunk sym for given days but only :year, :quarter, :month" do
|
69
89
|
(356..376).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:year) }
|
70
90
|
(86..96).each { |d| expect(Period.days_to_chunk_sym(d)).to eq(:quarter) }
|
@@ -76,7 +96,10 @@ describe Period do
|
|
76
96
|
it "should know what to call a chunk based on its size" do
|
77
97
|
expect(Period.new('2011-01-01', '2011-12-31').chunk_name).to eq('Year')
|
78
98
|
expect(Period.new('2011-01-01', '2011-03-31').chunk_name).to eq('Quarter')
|
99
|
+
expect(Period.new('2011-01-01', '2011-02-28').chunk_name).to eq('Bi-month')
|
79
100
|
expect(Period.new('2011-01-01', '2011-01-31').chunk_name).to eq('Month')
|
101
|
+
expect(Period.new('2011-01-01', '2011-01-15').chunk_name).to eq('Semi-month')
|
102
|
+
expect(Period.new('2011-01-09', '2011-01-22').chunk_name).to eq('Bi-week')
|
80
103
|
expect(Period.new('2011-01-01', '2011-01-07').chunk_name).to eq('Week')
|
81
104
|
expect(Period.new('2011-01-01', '2011-01-01').chunk_name).to eq('Day')
|
82
105
|
expect(Period.new('2011-01-01', '2011-01-21').chunk_name).to eq('Period')
|
@@ -104,13 +127,13 @@ describe Period do
|
|
104
127
|
end
|
105
128
|
|
106
129
|
describe "instance methods" do
|
107
|
-
|
108
130
|
it "should be able to compare for equality" do
|
109
131
|
pp1 = Period.new('2013-01-01', '2013-12-31')
|
110
132
|
pp2 = Period.new('2013-01-01', '2013-12-31')
|
111
133
|
pp3 = Period.new('2013-01-01', '2013-12-30')
|
112
134
|
expect((pp1 == pp2)).to be true
|
113
135
|
expect((pp1 == pp3)).to_not be true
|
136
|
+
expect((pp1 != pp3)).to be true
|
114
137
|
end
|
115
138
|
|
116
139
|
it "should be able to convert into a Range" do
|
@@ -141,11 +164,37 @@ describe Period do
|
|
141
164
|
}.not_to raise_error
|
142
165
|
end
|
143
166
|
|
167
|
+
it "should be able to tell if it contains a date with ===" do
|
168
|
+
pp = Period.new('2013-01-01', '2013-12-31')
|
169
|
+
expect(pp === Date.parse('2013-01-01')).to be true
|
170
|
+
expect(pp === Date.parse('2013-07-04')).to be true
|
171
|
+
expect(pp === Date.parse('2013-12-31')).to be true
|
172
|
+
expect(pp === Date.parse('2012-07-04')).to be false
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should know its size" do
|
176
|
+
pp = Period.new('2013-01-01', '2013-12-31')
|
177
|
+
expect(pp.size).to eq 365
|
178
|
+
expect(pp.length).to eq 365
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should implement the each method" do
|
182
|
+
pp = Period.new('2013-12-01', '2013-12-31')
|
183
|
+
pp.map { |dt| dt.iso }
|
184
|
+
.each { |s| expect(s).to match(/\d{4}-\d\d-\d\d/) }
|
185
|
+
end
|
186
|
+
|
144
187
|
it "should be able to make a concise period string" do
|
145
188
|
expect(Period.new('2013-01-01', '2013-12-31').to_s).to eq('2013')
|
146
189
|
expect(Period.new('2013-04-01', '2013-06-30').to_s).to eq('2013-2Q')
|
147
190
|
expect(Period.new('2013-03-01', '2013-03-31').to_s).to eq('2013-03')
|
148
|
-
expect(Period.new('2013-03-11', '2013-10-31').to_s)
|
191
|
+
expect(Period.new('2013-03-11', '2013-10-31').to_s)
|
192
|
+
.to eq('2013-03-11 to 2013-10-31')
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should be able to make a TeX string" do
|
196
|
+
expect(Period.new('2013-01-01', '2013-12-31').tex_quote)
|
197
|
+
.to eq('2013-01-01--2013-12-31')
|
149
198
|
end
|
150
199
|
|
151
200
|
# Note in the following that first period must begin within self.
|
@@ -323,6 +372,60 @@ describe Period do
|
|
323
372
|
expect(Period.new('2013-11-02', '2013-12-16').chunk_sym).to eq(:irregular)
|
324
373
|
end
|
325
374
|
|
375
|
+
it "should know if it's a subset of another period" do
|
376
|
+
year = Period.parse_spec('this_year')
|
377
|
+
month = Period.parse_spec('this_month')
|
378
|
+
expect(month.subset_of?(year)).to be true
|
379
|
+
expect(year.subset_of?(year)).to be true
|
380
|
+
end
|
381
|
+
|
382
|
+
it "should know if it's a proper subset of another period" do
|
383
|
+
year = Period.parse_spec('this_year')
|
384
|
+
month = Period.parse_spec('this_month')
|
385
|
+
expect(month.proper_subset_of?(year)).to be true
|
386
|
+
expect(year.proper_subset_of?(year)).to be false
|
387
|
+
end
|
388
|
+
|
389
|
+
it "should know if it's a superset of another period" do
|
390
|
+
year = Period.parse_spec('this_year')
|
391
|
+
month = Period.parse_spec('this_month')
|
392
|
+
expect(year.superset_of?(month)).to be true
|
393
|
+
expect(year.superset_of?(year)).to be true
|
394
|
+
end
|
395
|
+
|
396
|
+
it "should know if it's a proper superset of another period" do
|
397
|
+
year = Period.parse_spec('this_year')
|
398
|
+
month = Period.parse_spec('this_month')
|
399
|
+
expect(year.proper_superset_of?(month)).to be true
|
400
|
+
expect(year.proper_superset_of?(year)).to be false
|
401
|
+
end
|
402
|
+
|
403
|
+
it "should know if it overlaps another period" do
|
404
|
+
period1 = Period.parse_spec('2013')
|
405
|
+
period2 = Period.parse_spec('2012-10', '2013-03')
|
406
|
+
period3 = Period.parse_spec('2014')
|
407
|
+
expect(period1.overlaps?(period2)).to be true
|
408
|
+
expect(period2.overlaps?(period1)).to be true
|
409
|
+
expect(period1.overlaps?(period3)).to be false
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should know whether an array of periods have overlaps within it" do
|
413
|
+
months = (1..12).to_a.map{ |k| Period.parse_spec("2013-#{k}") }
|
414
|
+
year = Period.parse_spec("2013")
|
415
|
+
expect(year.has_overlaps_within?(months)).to be false
|
416
|
+
months << Period.parse_spec("2013-09-15", "2013-10-02")
|
417
|
+
expect(year.has_overlaps_within?(months)).to be true
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should know whether an array of periods span it" do
|
421
|
+
months = (1..12).to_a.map{ |k| Period.parse_spec("2013-#{k}") }
|
422
|
+
year = Period.parse_spec("2013")
|
423
|
+
expect(year.spanned_by?(months)).to be true
|
424
|
+
|
425
|
+
months = (2..12).to_a.map{ |k| Period.parse_spec("2013-#{k}") }
|
426
|
+
expect(year.spanned_by?(months)).to be false
|
427
|
+
end
|
428
|
+
|
326
429
|
it "should know its intersection with other period" do
|
327
430
|
year = Period.parse_spec('this_year')
|
328
431
|
month = Period.parse_spec('this_month')
|
data/spec/lib/string_spec.rb
CHANGED
@@ -55,75 +55,142 @@ the people, for the people, shall not perish from the earth."
|
|
55
55
|
##123456789012345678901234567890123456789012345678901234567890123456789|
|
56
56
|
end
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
describe "class methods" do
|
59
|
+
it "should be able to generate a random string" do
|
60
|
+
ss = String.random(100)
|
61
|
+
expect(ss.class).to eq String
|
62
|
+
expect(ss.size).to eq 100
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
describe "instance methods" do
|
67
|
+
it "should be able to convert a digital date to iso form" do
|
68
|
+
expect("20140521".digdate2iso).to eq '2014-05-21'
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
expect(l).to match(/^ /)
|
70
|
-
end
|
71
|
-
second_line = ' ' * 10 + 'nent a new nation'
|
72
|
-
third_line = ' ' * 10 + 'e proposition'
|
73
|
-
twenty_fourth_line = ' ' * 10 + 'eople, by the people, for the people'
|
74
|
-
expect(@getty.wrap(70, 10).split("\n")[1]).to match(/^#{second_line}/)
|
75
|
-
expect(@getty.wrap(70, 10).split("\n")[2]).to match(/^#{third_line}/)
|
76
|
-
expect(@getty.wrap(70, 10).split("\n")[23]).to match(/^#{twenty_fourth_line}/)
|
77
|
-
end
|
71
|
+
it "should wrap a short string" do
|
72
|
+
expect("hello, world".wrap).to eq "hello, world"
|
73
|
+
end
|
78
74
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
expect("<hello>".tex_quote).to eq("\\textless{}hello\\textgreater{}")
|
83
|
-
expect("{hello}".tex_quote).to eq("\\{hello\\}")
|
84
|
-
end
|
75
|
+
it "should wrap a long string" do
|
76
|
+
@getty.wrap.split("\n").each {|l| expect(l.length).to be <= 70}
|
77
|
+
end
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
it "should wrap a long string with a hangining indent" do
|
80
|
+
@getty.wrap(70, 10).split("\n").each {|l| expect(l.length).to be <= 70}
|
81
|
+
@getty.wrap(70, 10).split("\n")[1..-1].each do |l|
|
82
|
+
expect(l).to match(/^ /)
|
83
|
+
end
|
84
|
+
second_line = ' ' * 10 + 'nent a new nation'
|
85
|
+
third_line = ' ' * 10 + 'e proposition'
|
86
|
+
twenty_fourth_line = ' ' * 10 + 'eople, by the people, for the people'
|
87
|
+
expect(@getty.wrap(70, 10).split("\n")[1]).to match(/^#{second_line}/)
|
88
|
+
expect(@getty.wrap(70, 10).split("\n")[2]).to match(/^#{third_line}/)
|
89
|
+
expect(@getty.wrap(70, 10).split("\n")[23]).to match(/^#{twenty_fourth_line}/)
|
90
|
+
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
it "should be able to quote special TeX characters" do
|
93
|
+
expect("$10,000".tex_quote).to eq("\\$10,000")
|
94
|
+
expect("would~~have".tex_quote).to eq("would\\textasciitilde{}\\textasciitilde{}have")
|
95
|
+
expect("<hello>".tex_quote).to eq("\\textless{}hello\\textgreater{}")
|
96
|
+
expect("{hello}".tex_quote).to eq("\\{hello\\}")
|
97
|
+
end
|
95
98
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
it "should be able to convert a string to a regular expression" do
|
100
|
+
re = "/hello((\s+)(world))?/".to_regexp
|
101
|
+
expect(re.class).to eq Regexp
|
102
|
+
expect(re.casefold?).to be true
|
103
|
+
expect(re.multiline?).to be false
|
100
104
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
+
re = "/hello((\s+)(world))?/Im".to_regexp
|
106
|
+
expect(re.class).to eq Regexp
|
107
|
+
expect(re.casefold?).to be false
|
108
|
+
expect(re.multiline?).to be true
|
105
109
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
+
# Works without /../ but no options possible
|
111
|
+
re = "hello((\s+)(world))?".to_regexp
|
112
|
+
expect(re.class).to eq Regexp
|
113
|
+
expect(re.casefold?).to be false
|
114
|
+
expect(re.multiline?).to be false
|
115
|
+
end
|
110
116
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
117
|
+
it "should be able to convert itself to a sym" do
|
118
|
+
expect("joke".as_sym).to eq :joke
|
119
|
+
expect("hello world".as_sym).to eq :hello_world
|
120
|
+
expect("hello world it's me".as_sym).to eq :hello_world_its_me
|
121
|
+
end
|
116
122
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
+
it "should do nothing in response to as_string" do
|
124
|
+
expect("joke".as_string).to eq "joke"
|
125
|
+
expect("hello world".as_string).to eq "hello world"
|
126
|
+
expect("hello world it's me".as_string)
|
127
|
+
.to eq "hello world it's me"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be able to fuzzy match with another string" do
|
131
|
+
expect("Hello, world".fuzzy_match('or')).to be_truthy
|
132
|
+
expect("Hello, world".fuzzy_match('ox')).to be_falsy
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should be able to match with another string containing re" do
|
136
|
+
expect("Hello, world".matches_with('/or/')).to be_truthy
|
137
|
+
expect("Hello, world".matches_with('/ox/')).to be_falsy
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should be able to match with another string containing string" do
|
141
|
+
expect("Hello, world".matches_with('or')).to be_truthy
|
142
|
+
expect("Hello, world".matches_with('ox')).to be_falsy
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should be able to fuzzy match space-separated parts" do
|
146
|
+
expect("Hello world".fuzzy_match('hel or')).to be_truthy
|
147
|
+
expect("Hello, world".fuzzy_match('hel ox')).to be_falsy
|
148
|
+
end
|
123
149
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
150
|
+
it "should be able to fuzzy match colon-separated parts" do
|
151
|
+
expect("Hello:world".fuzzy_match('hel:or')).to be_truthy
|
152
|
+
expect("Hello:world".fuzzy_match('hel:ox')).to be_falsy
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should be able to fuzzy match colon-separated parts" do
|
156
|
+
expect("Hello:world".fuzzy_match('hel:or')).to be_truthy
|
157
|
+
expect("Hello:world".fuzzy_match('hel:ox')).to be_falsy
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should return the matched text" do
|
161
|
+
expect("Hello:world".fuzzy_match('hel')).to eq('Hel')
|
162
|
+
expect("Hello:world".fuzzy_match('hel:or')).to eq('Hello:wor')
|
163
|
+
expect("Hello:world".matches_with('/^h.*r/')).to eq('Hello:wor')
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should ignore periods, commas, and apostrophes when matching" do
|
167
|
+
expect("St. Luke's".fuzzy_match('st lukes')).to eq('St Lukes')
|
168
|
+
expect("St Lukes".fuzzy_match('st. luke\'s')).to eq('St Lukes')
|
169
|
+
expect("St Lukes, Inc.".fuzzy_match('st luke inc')).to eq('St Lukes Inc')
|
170
|
+
expect("E*TRADE".fuzzy_match('etrade')).to eq('ETRADE')
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should be able to properly capitalize a string as a title" do
|
174
|
+
# Capitalize little words only at beginning and end
|
175
|
+
expect("the cat in the hat".entitle).to eq('The Cat in the Hat')
|
176
|
+
expect("dr".entitle).to eq('Dr')
|
177
|
+
expect("cr".entitle).to eq('Cr')
|
178
|
+
# Don't capitalize c/o
|
179
|
+
expect("IBM c/o watson".entitle).to eq('Ibm c/o Watson')
|
180
|
+
# Capitlaize p.o.
|
181
|
+
expect("p.o. box 123".entitle).to eq('P.O. Box 123')
|
182
|
+
# Don't capitalize ordinals
|
183
|
+
expect("22nd of september".entitle).to eq('22nd of September')
|
184
|
+
# Capitalize common abbrevs
|
185
|
+
expect("US BANK".entitle).to eq('US Bank')
|
186
|
+
expect("NW territory".entitle).to eq('NW Territory')
|
187
|
+
# Leave word starting with numbers alone
|
188
|
+
expect("apartment 33-B".entitle).to eq('Apartment 33-B')
|
189
|
+
# Assume all consanants is an acronym
|
190
|
+
expect("the cbs network".entitle).to eq('The CBS Network')
|
191
|
+
# Capitalize both parts of a hyphenated word
|
192
|
+
expect("the hitler-stalin pact".entitle).
|
193
|
+
to eq('The Hitler-Stalin Pact')
|
194
|
+
end
|
128
195
|
end
|
129
196
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Symbol do
|
4
|
+
it "should be able to convert to a capitalized string" do
|
5
|
+
expect(:i_am_a_symbol.entitle).to eq 'I Am a Symbol'
|
6
|
+
expect(:i_am_a_symbol.to_string).to eq 'I Am a Symbol'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should respond to tex_quote" do
|
10
|
+
expect(:i_am_a_symbol.tex_quote).to eq 'i\\_am\\_a\\_symbol'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond to :as_sym as identity" do
|
14
|
+
expect(:i_am_a_symbol.as_sym).to eq :i_am_a_symbol
|
15
|
+
end
|
16
|
+
end
|
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: 0.1.
|
4
|
+
version: 0.1.12
|
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: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -166,12 +166,17 @@ files:
|
|
166
166
|
- lib/fat_core/string.rb
|
167
167
|
- lib/fat_core/symbol.rb
|
168
168
|
- lib/fat_core/version.rb
|
169
|
+
- spec/lib/array_spec.rb
|
169
170
|
- spec/lib/date_spec.rb
|
171
|
+
- spec/lib/enumerable_spec.rb
|
172
|
+
- spec/lib/hash_spec.rb
|
170
173
|
- spec/lib/kernel_spec.rb
|
174
|
+
- spec/lib/nil_spec.rb
|
171
175
|
- spec/lib/numeric_spec.rb
|
172
176
|
- spec/lib/period_spec.rb
|
173
177
|
- spec/lib/range_spec.rb
|
174
178
|
- spec/lib/string_spec.rb
|
179
|
+
- spec/lib/symbol_spec.rb
|
175
180
|
- spec/spec_helper.rb
|
176
181
|
homepage: ''
|
177
182
|
licenses:
|
@@ -198,11 +203,16 @@ signing_key:
|
|
198
203
|
specification_version: 4
|
199
204
|
summary: fat_core provides some useful core extensions
|
200
205
|
test_files:
|
206
|
+
- spec/lib/array_spec.rb
|
201
207
|
- spec/lib/date_spec.rb
|
208
|
+
- spec/lib/enumerable_spec.rb
|
209
|
+
- spec/lib/hash_spec.rb
|
202
210
|
- spec/lib/kernel_spec.rb
|
211
|
+
- spec/lib/nil_spec.rb
|
203
212
|
- spec/lib/numeric_spec.rb
|
204
213
|
- spec/lib/period_spec.rb
|
205
214
|
- spec/lib/range_spec.rb
|
206
215
|
- spec/lib/string_spec.rb
|
216
|
+
- spec/lib/symbol_spec.rb
|
207
217
|
- spec/spec_helper.rb
|
208
218
|
has_rdoc:
|