gstring 4.0.0 → 4.1.0

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: c8c020dd94769068e85f9925353e9d710708b11d
4
- data.tar.gz: 062eea3313e009d9ed8136f2c329265b51d8083a
3
+ metadata.gz: 22ec0aa515ef8ec1ebdad58c054842982ca2aec4
4
+ data.tar.gz: dddaf43b327100f2a87ce61f837ed652ff1eef39
5
5
  SHA512:
6
- metadata.gz: 37f685b2bc067c0a7305633231853e2fcacaca6f47c188db6c60eb4ea77a0787b59ce11a190ebee8841e97c5f84cfa829bcf39d90107fd002e9d37a26002266a
7
- data.tar.gz: c4546345771fbbd250db4c7a977f2dc25a91afc8d753e815ea28f493d4acf8e579cf3423c855a0b74b6cad941c040c126f860e6ab52ecab5fac72263953a3a25
6
+ metadata.gz: 205d47ad0dfc0ede71e61d0f585cde5967ac4899f552682a85866e57463309e5f0526b00b3033d7065632b917ed4ca83b4708e54c86d12945f5c9fb44abbb6bb
7
+ data.tar.gz: 22f8c5b4bdefdb73ee7a396a157a385db2478809b7af21441d08302d4e241cecf386e6377bcc9f00b1434cbe01ccd6018869db403976cc1e16b90c97c805c0fd
@@ -9,11 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Bryan Colvin"]
10
10
  spec.email = ["bryan@bdlsys.com"]
11
11
  spec.description = %q{
12
- Adds 60+ new methods to the base String class. Most help with parsing, others are more of a hodgepodge of nifty utilities.
12
+ Adds 80+ new methods to the base String class. Most help with parsing, others are more of a hodgepodge of nifty utilities.
13
13
  Utilities include: engineering_notation, cryptogram generator, password generator, sort by embedded numbers, etc.
14
14
  Some represent some of the better ideas from other string related gems.
15
15
  Most are from 20 years of multiple language string extensions that were used in some project.}
16
- spec.summary = %q{Adds 60+ new methods String class.}
16
+ spec.summary = %q{Adds 70+ new methods String class.}
17
17
  spec.homepage = "http://bdlsys.com/gems/gstring.html"
18
18
  spec.license = "MIT"
19
19
 
@@ -167,6 +167,38 @@ class String
167
167
  end
168
168
  return rtn
169
169
  end
170
+
171
+ SET_LIKE_KEEP = SET_CHARS | SET_INT_CHARS | "*-'"
172
+ #-------------------------------------------------
173
+ def like(table_class_name, table_column_name, mode_and=true, kp = SET_LIKE_KEEP)
174
+ ary = []
175
+ self.split.each do |substr|
176
+ str = substr.keep kp
177
+ if (str.first=='*')
178
+ str.first!
179
+ if (str.last=='*')
180
+ str.last!
181
+ ary.push "%#{str}%".gsub('*', '%')
182
+ else
183
+ ary.push "%#{str}".gsub('*', '%')
184
+ end
185
+ elsif (str.last=='*')
186
+ str.last!
187
+ ary.push "#{str}%".gsub('*', '%')
188
+ else
189
+ ary.push "%#{str}%".gsub('*', '%')
190
+ end
191
+ end #each
192
+ md = mode_and ? ' and ' : ' or '
193
+ qry = (["`#{table_column_name}` like ?"] * ary.count).join md
194
+ return table_class_name.where(qry, *ary)
195
+ end
196
+
197
+ R_RATED = /(cum[\-_s5]|pi[s5][s5]|f.ck|4k.r|whore|slut|sh[iy]t|n[i1l][g9][g9]er|qqqq|my.*a[sz]|ph.ck|dick|vagina|a[sz5][sz5].*wipe|a[sz5][sz5].*hole|penis|b4i4q)/i
198
+
199
+ def clean?(rgx = R_RATED)
200
+ return self.scan(rgx).empty?
201
+ end
170
202
 
171
203
  def upcase?
172
204
  set = self.to_bset
@@ -378,6 +410,23 @@ class String
378
410
  dup.condense!
379
411
  end
380
412
 
413
+ def push(str)
414
+ replace(self+str).dup
415
+ end
416
+
417
+ def pop(nchars=1)
418
+ if (nchars < 1) # avoid silly requests
419
+ return ""
420
+ elsif (nchars >= length)
421
+ rtn = dup
422
+ replace ""
423
+ return rtn
424
+ end
425
+ rtn = self[-nchars..-1]
426
+ replace self[0..(length-nchars-1)]
427
+ return rtn
428
+ end
429
+
381
430
  def sort
382
431
  self.split('').sort.join('')
383
432
  end
@@ -569,7 +618,19 @@ end
569
618
  str = dup
570
619
  str.remove!(obj, *prm)
571
620
  return str
572
- end
621
+ end
622
+
623
+ def keep(ks) # only keep chars belonging to set
624
+ rtn = ""
625
+ self.each_char do |ch|
626
+ rtn += ch if ks.include? ch
627
+ end
628
+ return rtn
629
+ end
630
+
631
+ def keep!(ks)
632
+ replace keep(ks)
633
+ end
573
634
 
574
635
  def extract!(prm=1, fill_hole="")
575
636
  return "" if empty?
@@ -1322,35 +1383,148 @@ end
1322
1383
  return parsed.to_f
1323
1384
  end
1324
1385
  end
1386
+
1387
+ def to_crlf
1388
+ rtn = ""
1389
+ state = :normal
1390
+ each_char do |ch|
1391
+ if :normal == state
1392
+ if "\r" == ch
1393
+ state = :r_pending
1394
+ elsif "\n" == ch
1395
+ rtn += "\r\n"
1396
+ else
1397
+ rtn += ch
1398
+ end
1399
+ else
1400
+ if "\n" == ch
1401
+ rtn += "\r\n"
1402
+ else
1403
+ rtn += "\r"
1404
+ rtn += ch
1405
+ end
1406
+ state = :normal
1407
+ end
1408
+ end
1409
+ return rtn
1410
+ end
1325
1411
 
1326
- def wrap_to(len, *flags)
1327
- if (self.length < len)
1328
- if flags.include? :array
1329
- return [self.dup]
1412
+ def to_lf # convert \r\n to \n
1413
+ rtn = ""
1414
+ state = :normal
1415
+ each_char do |ch|
1416
+ if :normal == state
1417
+ if "\r" == ch
1418
+ state = :r_pending
1419
+ elsif "\n" == ch
1420
+ rtn += "\012"
1421
+ else
1422
+ rtn += ch
1423
+ end
1330
1424
  else
1331
- return self.dup
1425
+ if "\n" == ch
1426
+ rtn += "\n"
1427
+ else
1428
+ rtn += "\r"
1429
+ rtn += ch
1430
+ end
1431
+ state = :normal
1332
1432
  end
1333
1433
  end
1434
+ return rtn
1435
+ end
1436
+
1437
+ def to_crlf!
1438
+ self.replace to_crlf
1439
+ self
1440
+ end
1441
+
1442
+ def to_lf! # removes \r
1443
+ self.replace to_lf
1444
+ self
1445
+ end
1446
+
1447
+ SET_COMPACT_RIGHT = "<[{(".to_bset
1448
+ SET_COMPACT_LEFT = ".,!?:;>]})'\"\\/|-_+".to_bset
1449
+
1450
+ def compact(sl=SET_COMPACT_LEFT, sr=SET_COMPACT_RIGHT)
1451
+ #sl = sl.to_bset
1452
+ #sr = sr.to_bset
1453
+ rtn = ""
1454
+ state = :start
1455
+ each_char do |ch|
1456
+ if :start == state
1457
+ next if ch <= ' '
1458
+ state = state = sr.include?(ch) ? :right : :add
1459
+ rtn += ch
1460
+ elsif :add == state
1461
+ if ch <= ' '
1462
+ state = :zap
1463
+ rtn += ' '
1464
+ elsif sr.include? ch
1465
+ state = :right
1466
+ rtn += ch
1467
+ else
1468
+ rtn += ch
1469
+ end
1470
+ elsif :right == state
1471
+ unless ch <= ' '
1472
+ rtn += ch
1473
+ state = sr.include?(ch) ? :right : :add
1474
+ end
1475
+ else
1476
+ #elsif :zap == state
1477
+ next if ch <= ' '
1478
+ rtn.pop if sl.include? ch
1479
+ # state = :add
1480
+ state = sr.include?(ch) ? :right : :add
1481
+ rtn += ch
1482
+ end
1483
+ end
1484
+ rtn.pop if rtn.last==' '
1485
+ return rtn
1486
+ end
1487
+
1488
+ def compact!(sl=SET_COMPACT_LEFT, sr=SET_COMPACT_RIGHT)
1489
+ replace compact(sl, sr)
1490
+ end
1491
+
1492
+
1493
+
1494
+ def wrap_to(len, *flags)
1495
+ # remove this as cr will mess things up
1496
+ # the logic below will need to be inferred as needed
1497
+ #if (self.length < len)
1498
+ # if flags.include? :array
1499
+ # return [self.dup]
1500
+ # else
1501
+ # return self.dup
1502
+ # end
1503
+ #end
1334
1504
  ary = []
1335
- str = self.dup
1505
+ str = self.to_lf # remove messy \r if present
1336
1506
  if flags.include? :approximate
1337
1507
  loop do
1338
1508
  tar = str.find_near(len)
1509
+ tmp = str.find("\n")
1510
+ unless tmp.nil?
1511
+ tar = [tmp,tmp] if tmp <= len
1512
+ end
1339
1513
  # now for the nasty end points and edge cases
1340
1514
  if tar.first.nil?
1341
1515
  if tar.last.nil?
1342
- ary.push str.extract! len
1516
+ ary.push str.extract!(len)
1343
1517
  else
1344
- ary.push str.extract! tar.last + 1
1518
+ ary.push str.extract!(tar.last + 1)
1345
1519
  end
1346
1520
  else
1347
1521
  if tar.last.nil?
1348
- ary.push str.extract! tar.first + 1
1522
+ ary.push str.extract!(tar.first + 1)
1349
1523
  else # find closest fit
1350
1524
  if (len - tar.first) <= (tar.last - len)
1351
- ary.push str.extract! tar.first + 1
1525
+ ary.push str.extract!(tar.first + 1)
1352
1526
  else
1353
- ary.push str.extract! tar.last + 1
1527
+ ary.push str.extract!(tar.last + 1)
1354
1528
  end
1355
1529
  end
1356
1530
  end
@@ -1359,16 +1533,20 @@ end
1359
1533
  else
1360
1534
  loop do
1361
1535
  tar = str.rindex(String::SET_SPLIT_CHARS, len)
1536
+ tmp = str.find("\n")
1537
+ unless tmp.nil?
1538
+ tar = tmp if tmp <= len
1539
+ end
1362
1540
  if (tar.nil?)
1363
- ary.push str.extract! len
1541
+ ary.push str.extract!(len)
1364
1542
  else
1365
- ary.push str.extract! tar+1
1543
+ ary.push str.extract!(tar+1)
1366
1544
  end
1367
1545
  break if str.length <= len
1368
1546
  end #loop
1369
1547
  end #if
1370
1548
  ary.push str
1371
- ary.length.times { |ii| ary[ii].rstrip! }
1549
+ ary.length.times { |ii| ary[ii].strip! } unless flags.include? :no_strip
1372
1550
  return ary if flags.include? :array
1373
1551
  if flags.include? :html
1374
1552
  str = ary.join '<br />'
@@ -1,3 +1,3 @@
1
1
  module Gstring
2
- VERSION = "4.0.0"
2
+ VERSION = "4.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gstring
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Colvin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-29 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: setfu
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 5.0.0
83
- description: "\nAdds 60+ new methods to the base String class. Most help with parsing,
83
+ description: "\nAdds 80+ new methods to the base String class. Most help with parsing,
84
84
  others are more of a hodgepodge of nifty utilities.\nUtilities include: engineering_notation,
85
85
  cryptogram generator, password generator, sort by embedded numbers, etc. \nSome
86
86
  represent some of the better ideas from other string related gems.\nMost are from
@@ -119,8 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  version: '0'
120
120
  requirements: []
121
121
  rubyforge_project:
122
- rubygems_version: 2.4.8
122
+ rubygems_version: 2.5.1
123
123
  signing_key:
124
124
  specification_version: 4
125
- summary: Adds 60+ new methods String class.
125
+ summary: Adds 70+ new methods String class.
126
126
  test_files: []