epitools 0.5.96 → 0.5.97

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: 6bc0ff24a8ad6f3dc81034a1d358c5fc1f7130ac
4
- data.tar.gz: b834243e264b44d0fa33492e6e80697342d558ee
3
+ metadata.gz: bcb7b057dfd89a787a892fbbc839c89a2a2b2213
4
+ data.tar.gz: 0bf96917183fd8298ff61d399444567993d07de0
5
5
  SHA512:
6
- metadata.gz: 1108d095b65008e83a72b7e2f3904067550804e57d9d4351905f77aea5ffdf1880df671f161353ce2eade31a3c507c2311ca96e5bc20202b0d1f88af2bf363e4
7
- data.tar.gz: f597a50f0cb08bf959db4c05f416de5bbd9ba9ca1219cc907800c2d9942535a9c02fb599c0f9572e26b0b7baba3e211843a71cce1ece531aab08e2c5d7fc159b
6
+ metadata.gz: 42fbcc5fe50f0a1b2eb7b49156f73ccb108d70560b3c57bcccd7224686ca5417aef2a83133c5e3cc7ac6c112734200e2b60a22cca5eaa1d35fbe92b5fdbd6214
7
+ data.tar.gz: aba4e219db005393dce44cc1712ed31828b65f1e678d96cd7b77a9c60eff0e8bb6f007e314916e847ec247a0f982a81d778dccf4451c9c66749737709f062977
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.96
1
+ 0.5.97
@@ -10,7 +10,7 @@ class String
10
10
  def to_unix
11
11
  gsub("\r\n", "\n")
12
12
  end
13
-
13
+
14
14
  #
15
15
  # Remove redundant whitespaces (not including newlines).
16
16
  #
@@ -63,7 +63,7 @@ class String
63
63
  #
64
64
  def contains_color?
65
65
  self[COLOR_REGEXP]
66
- end
66
+ end
67
67
  alias_method :contains_colors?, :contains_color?
68
68
  alias_method :contains_ansi?, :contains_color?
69
69
 
@@ -73,7 +73,7 @@ class String
73
73
  def strip_color
74
74
  gsub(COLOR_REGEXP, '')
75
75
  end
76
- alias_method :strip_ansi, :strip_color
76
+ alias_method :strip_ansi, :strip_color
77
77
 
78
78
  #
79
79
  # Like #each_line, but skips empty lines and removes \n's.
@@ -82,7 +82,7 @@ class String
82
82
  # note: $/ is the platform's newline separator
83
83
  split($/).select{|l| not l.blank? }
84
84
  end
85
-
85
+
86
86
  alias_method :nicelines, :nice_lines
87
87
  alias_method :clean_lines, :nice_lines
88
88
 
@@ -171,7 +171,7 @@ class String
171
171
 
172
172
 
173
173
  #
174
- # Wrap all lines at window size, and indent
174
+ # Wrap all lines at window size, and indent
175
175
  #
176
176
  def wrap_and_indent(prefix, width=nil)
177
177
  prefix = " "*prefix if prefix.is_a? Numeric
@@ -207,14 +207,14 @@ class String
207
207
  def rot13
208
208
  tr('n-za-mN-ZA-M', 'a-zA-Z')
209
209
  end
210
-
210
+
211
211
  #
212
212
  # Convert non-URI characters into %XXes.
213
213
  #
214
214
  def urlencode
215
215
  URI.escape(self)
216
216
  end
217
-
217
+
218
218
  #
219
219
  # Convert an URI's %XXes into regular characters.
220
220
  #
@@ -240,20 +240,28 @@ class String
240
240
  params.map_values { |v| v.size > 1 ? v : v.first }
241
241
  end
242
242
 
243
+ #
244
+ # Raw bytes to an integer (as big as necessary)
245
+ #
246
+ def to_i_from_bytes(big_endian=false)
247
+ bs = reverse ? bytes.reverse_each : bytes.each
248
+ bs.with_index.inject(0) { |sum,(b,i)| (b << (8*i)) + sum }
249
+ end
250
+
243
251
  #
244
252
  # Cached constants for base62 decoding.
245
- #
253
+ #
246
254
  BASE62_DIGITS = Hash[ Integer::BASE62_DIGITS.zip((0...Integer::BASE62_DIGITS.size).to_a) ]
247
255
  BASE62_BASE = Integer::BASE62_BASE
248
-
256
+
249
257
  #
250
258
  # Convert a string (encoded in base16 "hex" -- for example, an MD5 or SHA1 hash)
251
- # into "base62" format. (See Integer#to_base62 for more info.)
259
+ # into "base62" format. (See Integer#to_base62 for more info.)
252
260
  #
253
261
  def to_base62
254
262
  to_i(16).to_base62
255
263
  end
256
-
264
+
257
265
  #
258
266
  # Convert a string encoded in base62 into an integer.
259
267
  # (See Integer#to_base62 for more info.)
@@ -273,8 +281,8 @@ class String
273
281
  def from_base64
274
282
  unpack("m").first
275
283
  end
276
- alias_method :decode64, :from_base64
277
-
284
+ alias_method :decode64, :from_base64
285
+
278
286
  #
279
287
  # Encode into a mime64/base64 string
280
288
  #
@@ -286,25 +294,25 @@ class String
286
294
 
287
295
  #
288
296
  # MD5 the string
289
- #
297
+ #
290
298
  def md5
291
299
  Digest::MD5.hexdigest self
292
300
  end
293
-
301
+
294
302
  #
295
303
  # SHA1 the string
296
- #
304
+ #
297
305
  def sha1
298
306
  Digest::SHA1.hexdigest self
299
307
  end
300
-
308
+
301
309
  #
302
310
  # SHA256 the string
303
- #
311
+ #
304
312
  def sha256
305
313
  Digest::SHA256.hexdigest self
306
314
  end
307
-
315
+
308
316
  #
309
317
  # gzip the string
310
318
  #
@@ -313,7 +321,7 @@ class String
313
321
  Zlib::GzipWriter.wrap(zipped, level) { |io| io.write(self) }
314
322
  zipped.string
315
323
  end
316
-
324
+
317
325
  #
318
326
  # gunzip the string
319
327
  #
@@ -321,31 +329,31 @@ class String
321
329
  data = StringIO.new(self)
322
330
  Zlib::GzipReader.new(data).read
323
331
  end
324
-
332
+
325
333
  #
326
334
  # deflate the string
327
335
  #
328
336
  def deflate(level=nil)
329
337
  Zlib::Deflate.deflate(self, level)
330
338
  end
331
-
339
+
332
340
  #
333
341
  # inflate the string
334
342
  #
335
343
  def inflate
336
344
  Zlib::Inflate.inflate(self)
337
345
  end
338
-
339
- # `true` if this string starts with the substring
340
- #
346
+
347
+ # `true` if this string starts with the substring
348
+ #
341
349
  def startswith?(substring)
342
350
  self[0...substring.size] == substring
343
351
  end
344
352
  alias_method :startswith, :startswith?
345
-
353
+
354
+ #
355
+ # `true` if this string ends with the substring
346
356
  #
347
- # `true` if this string ends with the substring
348
- #
349
357
  def endswith?(substring)
350
358
  self[-substring.size..-1] == substring
351
359
  end
@@ -357,7 +365,7 @@ class String
357
365
  def from_json
358
366
  JSON.parse(self)
359
367
  end
360
-
368
+
361
369
  #
362
370
  # Parse this string as YAML
363
371
  #
@@ -367,7 +375,7 @@ class String
367
375
 
368
376
  #
369
377
  # Unmarshal the string (transform it into Ruby datatypes).
370
- #
378
+ #
371
379
  def unmarshal
372
380
  Marshal.restore self
373
381
  end
@@ -385,7 +393,7 @@ class String
385
393
  #
386
394
  def amount(n)
387
395
  case n
388
- when 0
396
+ when 0
389
397
  "0 #{self}s"
390
398
  when 1, -1
391
399
  "#{n} #{self}"
@@ -393,7 +401,7 @@ class String
393
401
  "#{n} #{self}s"
394
402
  end
395
403
  end
396
-
404
+
397
405
  #
398
406
  # Converts time duration strings (mm:ss, mm:ss.dd, hh:mm:ss, or dd:hh:mm:ss) to seconds.
399
407
  # (The reverse of Integer#to_hms)
@@ -407,7 +415,7 @@ class String
407
415
  nums_and_units = nums.reverse.zip %w[seconds minutes hours days]
408
416
  nums_and_units.map { |num, units| num.send(units) }.sum
409
417
  end
410
-
418
+
411
419
  #
412
420
  # Print a hexdump of the string to STDOUT (coloured, if the terminal supports it)
413
421
  #
@@ -415,10 +423,9 @@ class String
415
423
  Hex.dump(self)
416
424
  end
417
425
 
418
-
419
426
  unless public_method_defined? :to_proc
420
-
421
- #
427
+
428
+ #
422
429
  # String#to_proc
423
430
  #
424
431
  # See http://weblog.raganwald.com/2007/10/stringtoproc.html
@@ -430,7 +437,7 @@ class String
430
437
  #
431
438
  # (c) 2007 Reginald Braithwaite
432
439
  # Portions Copyright (c) 2006 Oliver Steele
433
- #
440
+ #
434
441
  # Permission is hereby granted, free of charge, to any person obtaining
435
442
  # a copy of this software and associated documentation files (the
436
443
  # "Software"), to deal in the Software without restriction, including
@@ -438,10 +445,10 @@ class String
438
445
  # distribute, sublicense, and/or sell copies of the Software, and to
439
446
  # permit persons to whom the Software is furnished to do so, subject to
440
447
  # the following conditions:
441
- #
448
+ #
442
449
  # The above copyright notice and this permission notice shall be
443
450
  # included in all copies or substantial portions of the Software.
444
- #
451
+ #
445
452
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
446
453
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
447
454
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -475,22 +482,21 @@ class String
475
482
  /(?:\b[A-Z]|\.[a-zA-Z_$])[a-zA-Z_$\d]*|[a-zA-Z_$][a-zA-Z_$\d]*:|self|arguments|'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"/, ''
476
483
  ).scan(
477
484
  /([a-z_$][a-z_$\d]*)/i
478
- ) do |v|
485
+ ) do |v|
479
486
  params.push(v) unless params.include?(v)
480
487
  end
481
488
  end
482
489
  eval_block("Proc.new { |#{params.join(', ')}| #{expr} }", block)
483
490
  end
484
491
  end
485
-
492
+
486
493
  private
487
-
494
+
488
495
  def eval_block(code, block)
489
496
  eval code, block && block.binding
490
497
  end
491
-
492
- end # unless public_method_defined? :to_proc
493
498
 
494
- end
499
+ end # unless public_method_defined? :to_proc
495
500
 
496
501
 
502
+ end
@@ -336,6 +336,16 @@ describe String do
336
336
  5.mulmod(2).should == [10, 0]
337
337
  end
338
338
 
339
+ it "to_i_from_byteses" do
340
+ i = 2**31
341
+
342
+ big_endian_bytes = [i].pack("L>")
343
+ little_endian_bytes = [i].pack("L<")
344
+
345
+ big_endian_bytes.to_i_from_bytes(true).should == i
346
+ little_endian_bytes.to_i_from_bytes.should == i
347
+ end
348
+
339
349
  end
340
350
 
341
351
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.96
4
+ version: 0.5.97
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-20 00:00:00.000000000 Z
11
+ date: 2016-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec