epitools 0.5.99 → 0.5.100
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/VERSION +1 -1
- data/lib/epitools/core_ext/array.rb +4 -7
- data/lib/epitools/core_ext/enumerable.rb +27 -0
- data/lib/epitools/path.rb +3 -24
- data/spec/core_ext_spec.rb +16 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ab55bd4da24b0248446b9a5ce73720500595a5
|
4
|
+
data.tar.gz: 21216bbed7ed7d2d62ee5f0e4f8c3ee55bbf1a41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1309e3223556495583e860b4c94389f6307b0cd5e8932a4af9e1eddb8dc7c3659b6884262d2076e559f9cbe466a97d7a0e1c21a85136be9f936af894a67d00c
|
7
|
+
data.tar.gz: 65f74192fa9eac491bf4e3a7a1be548fecb406190e76e250f2821215a6f1759bbfc46061deeba2c34249338d4ba608696667a8594ab089a695dcff1b9e42af14
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.100
|
@@ -44,14 +44,11 @@ class Array
|
|
44
44
|
end
|
45
45
|
|
46
46
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# eg:
|
50
|
-
# >> [5,39].rzip([:hours, :mins, :secs])
|
51
|
-
# => [ [:mins, 5], [:secs, 39] ]
|
47
|
+
# see: Enumerable#rzip
|
52
48
|
#
|
53
49
|
def rzip(other)
|
54
|
-
|
50
|
+
super.to_a
|
51
|
+
# reverse_each.zip(other.reverse_each).reverse_each.to_a
|
55
52
|
# reverse.zip(other.reverse).reverse # That's a lotta reverses!
|
56
53
|
end
|
57
54
|
|
@@ -166,7 +163,7 @@ class Array
|
|
166
163
|
# }
|
167
164
|
#
|
168
165
|
def histogram(n_buckets=10, options={})
|
169
|
-
|
166
|
+
|
170
167
|
use_ranges = options[:ranges] || options[:hash]
|
171
168
|
|
172
169
|
min_val = min
|
@@ -373,6 +373,19 @@ module Enumerable
|
|
373
373
|
end
|
374
374
|
end
|
375
375
|
|
376
|
+
#
|
377
|
+
# Reverse zip (aligns the ends of two arrays, and zipping them from the right-hand side)
|
378
|
+
#
|
379
|
+
# eg:
|
380
|
+
# >> [5,39].rzip([:hours, :mins, :secs])
|
381
|
+
# => [ [:mins, 5], [:secs, 39] ]
|
382
|
+
#
|
383
|
+
# Note: Like zip, it will pad the second array if it's shorter than the first
|
384
|
+
#
|
385
|
+
def rzip(other)
|
386
|
+
reverse_each.zip(other.reverse_each).reverse_each
|
387
|
+
end
|
388
|
+
|
376
389
|
#
|
377
390
|
# Does the opposite of #zip -- converts [ [:a, 1], [:b, 2] ] to [ [:a, :b], [1, 2] ]
|
378
391
|
#
|
@@ -409,6 +422,20 @@ module Enumerable
|
|
409
422
|
end
|
410
423
|
alias_method :group_neighbors_by, :group_neighbours_by
|
411
424
|
|
425
|
+
|
426
|
+
#
|
427
|
+
# Converts an array of 2-element key/value pairs into a Hash, grouped by key.
|
428
|
+
# (Like to_h, but the pairs can have duplicate keys.)
|
429
|
+
#
|
430
|
+
def grouped_to_h
|
431
|
+
result = Hash.of_arrays
|
432
|
+
each {|k,v| result[k] << v }
|
433
|
+
result
|
434
|
+
end
|
435
|
+
alias_method :group_to_h, :grouped_to_h
|
436
|
+
alias_method :to_h_in_groups, :grouped_to_h
|
437
|
+
alias_method :to_h_grouped, :grouped_to_h
|
438
|
+
|
412
439
|
#
|
413
440
|
# Convert the array into a stable iterator (Iter) object.
|
414
441
|
#
|
data/lib/epitools/path.rb
CHANGED
@@ -123,6 +123,9 @@ class Path
|
|
123
123
|
###############################################################################
|
124
124
|
|
125
125
|
def initialize(newpath, hints={})
|
126
|
+
send("path=", newpath, hints)
|
127
|
+
|
128
|
+
# p hints
|
126
129
|
if hints[:unlink_when_garbage_collected]
|
127
130
|
backup_path = path.dup
|
128
131
|
puts "unlinking #{backup_path} after gc!"
|
@@ -130,8 +133,6 @@ class Path
|
|
130
133
|
File.unlink backup_path
|
131
134
|
end
|
132
135
|
end
|
133
|
-
|
134
|
-
send("path=", newpath, hints)
|
135
136
|
end
|
136
137
|
|
137
138
|
def initialize_copy(other)
|
@@ -591,28 +592,6 @@ class Path
|
|
591
592
|
end
|
592
593
|
end
|
593
594
|
|
594
|
-
def media_tags
|
595
|
-
require 'taglib'
|
596
|
-
|
597
|
-
tags = nil
|
598
|
-
|
599
|
-
TagLib::FileRef.open(path) do |fileref|
|
600
|
-
unless fileref.null?
|
601
|
-
tags = fileref.tag
|
602
|
-
result = {}
|
603
|
-
getters = tags.class.instance_methods(false).group_by {|m| m[/^.+[^=]/] }.map { |k,vs| vs.size == 2 ? k.to_sym : nil }.compact
|
604
|
-
getters.each do |getter|
|
605
|
-
tags[getter] = tags.public_send(getter)
|
606
|
-
end
|
607
|
-
end
|
608
|
-
end
|
609
|
-
|
610
|
-
tags
|
611
|
-
end
|
612
|
-
|
613
|
-
alias_method :id3, :media_tags
|
614
|
-
alias_method :id3tags, :media_tags
|
615
|
-
|
616
595
|
#
|
617
596
|
# Retrieve one of this file's xattrs
|
618
597
|
#
|
data/spec/core_ext_spec.rb
CHANGED
@@ -468,7 +468,15 @@ describe Array do
|
|
468
468
|
end
|
469
469
|
|
470
470
|
it "rzips" do
|
471
|
-
[
|
471
|
+
in_times = [:hours, :mins, :secs]
|
472
|
+
in_tegers = [ 5, 39]
|
473
|
+
out_put = [[5, :mins], [39, :secs]]
|
474
|
+
|
475
|
+
in_tegers.rzip(in_times).should == out_put
|
476
|
+
|
477
|
+
enum = in_tegers.to_enum.rzip(in_times)
|
478
|
+
enum.is_a?(Enumerator).should == true
|
479
|
+
enum.to_a.should == [ [5, :mins], [39, :secs] ]
|
472
480
|
end
|
473
481
|
|
474
482
|
it "middles" do
|
@@ -614,6 +622,13 @@ describe Enumerable do
|
|
614
622
|
result.should == [[1,2],[5,6,7],[10,11],[13]]
|
615
623
|
end
|
616
624
|
|
625
|
+
it "grouped_to_h's" do
|
626
|
+
[[:a, 1], [:b, 2], [:a, 0]].grouped_to_h.should == {
|
627
|
+
a: [1,0],
|
628
|
+
b: [2]
|
629
|
+
}
|
630
|
+
end
|
631
|
+
|
617
632
|
it "includes?s" do
|
618
633
|
[:a, :b, :c].to_enum.includes?(:c).should == true
|
619
634
|
[:a, :b, :c].to_enum.includes?(5).should == false
|
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.
|
4
|
+
version: 0.5.100
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|