epitools 0.5.75 → 0.5.77

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: d52d4e8296e7da1393eec498cbaeed20dcb91037
4
- data.tar.gz: 8d7891b8dc7bce309d07a290559dcec183e49048
3
+ metadata.gz: 016e41602fa10ba734ecd653b8f8820ca9ab463f
4
+ data.tar.gz: 5a28bf973df796c3b138adf0f37d953deb9392f1
5
5
  SHA512:
6
- metadata.gz: 88e37b2e60fa947b5d5a6d4e9d82c105f552fec41139d707f2271e9d7309b3a9be08f2ba8bbbccb0230fa35bddc1bb6d6a16e847b041a977f2ddfc44c8c38756
7
- data.tar.gz: 6167c8d3cc00215751848926eb1931e036b208d6d7926dc88c45934ed5d9651d1a63a97a911c1ce1f927f0796d69d7b590b3b3f81f908f70c4615b454116ebb8
6
+ metadata.gz: cdd7391038d8a320c39f61fbd212bff08d411b91fcf6b0d3a066599d60c798254fb557c8bf6f5b52d8467db97c371e7f3ccf7cb9bb7af2ace8e7e14bfc41fe31
7
+ data.tar.gz: e9cf17e7cb8f47028752e2f6e84e8cbe3a3978b6657ca1ec952b19dfe95ea1a0f60362451aa4a210e0258ba6da533a27d99cedb2b9f0ea67a123a4d0669616d1
data/README.rdoc CHANGED
@@ -8,21 +8,21 @@ All epitools modules (and a bunch of Ruby's stdlib) are
8
8
  {loaded on demand with "autoload"}[https://github.com/epitron/epitools/blob/master/lib/epitools/autoloads.rb],
9
9
  so it's really fast. (Require this in your .irbrc or .pryrc, and you'll never have to require another Ruby stdlib module again!)
10
10
 
11
- Enhanced base classes: {Enumerable}[http://rdoc.info/github/epitron/epitools/master/Enumerable], {Hash}[http://rdoc.info/github/epitron/epitools/master/Hash], {String}[http://rdoc.info/github/epitron/epitools/master/String], {Array}[http://rdoc.info/github/epitron/epitools/master/Array], {File}[http://rdoc.info/github/epitron/epitools/master/File], {Object}[http://rdoc.info/github/epitron/epitools/master/Object], {Integer}[http://rdoc.info/github/epitron/epitools/master/Integer], etc.
11
+ Enhanced base classes: {Enumerable}[http://rdoc.info/gems/epitools/Enumerable], {Hash}[http://rdoc.info/gems/epitools/Hash], {String}[http://rdoc.info/gems/epitools/String], {Array}[http://rdoc.info/gems/epitools/Array], {File}[http://rdoc.info/gems/epitools/File], {Object}[http://rdoc.info/gems/epitools/Object], {Integer}[http://rdoc.info/gems/epitools/Integer], etc.
12
12
 
13
13
  Extras:
14
14
 
15
- * {Path}[http://rdoc.info/github/epitron/epitools/master/Path] (an object-oriented interface to the filesytem -- it's File, Dir, FileUtils, and Pathname all rolled into one!)
16
- * {Browser}[http://rdoc.info/github/epitron/epitools/master/Browser] (a fake browser, with a cache, cookies, download progress bars, plus the rest of the mechanize/nokogiri API you know and love)
17
- * {Colored}[http://rdoc.info/github/epitron/epitools/master/Colored] (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
18
- * {TypedStruct}[http://rdoc.info/github/epitron/epitools/master/TypedStruct] (like Struct, but setters always coerce input to a certain type, eg: boolean, integer, etc.)
19
- * {WM}[http://rdoc.info/github/epitron/epitools/master/WM] (control/query desktop windows in X. Note: `wmctrl` must be installed)
20
- * {Sys}[http://rdoc.info/github/epitron/epitools/master/Sys] (system tools -- determine operating system, list processes, view network statistics, etc.)
21
- * {Term}[http://rdoc.info/github/epitron/epitools/master/Term] (a toolbox for making terminal-based scripts -- get terminal size, create tables, etc.)
22
- * {Iter}[http://rdoc.info/github/epitron/epitools/master/Iter] (a "stable iterator" -- lets you write algorithms that modify the array as you're iterating; good for clustering.)
23
- * {Rash}[http://rdoc.info/github/epitron/epitools/master/Rash] (a hash which can have Regexps as keys, so that many input keys can map to a single value.)
24
- * {Progressbar}[http://rdoc.info/github/epitron/epitools/master/Progressbar] (better than the progressbar gem)
25
- * {MimeMagic}[http://rdoc.info/github/epitron/epitools/master/MimeMagic] (a port of the Unix `file` utility for automatically recognizing files based on their contents; faster than running `file` on every file if you have to process large batches of files. This is originally from the mimemagic gem by {Daniel Mendler}[https://github.com/minad], and has been slightly modified and enhanced.)
15
+ * {Path}[http://rdoc.info/gems/epitools/Path] (an object-oriented interface to the filesytem -- it's File, Dir, FileUtils, and Pathname all rolled into one!)
16
+ * {Browser}[http://rdoc.info/gems/epitools/Browser] (a fake browser, with a cache, cookies, download progress bars, plus the rest of the mechanize/nokogiri API you know and love)
17
+ * {Colored}[http://rdoc.info/gems/epitools/Colored] (enhanced version of defunkt's colored -- adds ANSI colouring methods to String, eg: #red, #green, #light_blue, etc.)
18
+ * {TypedStruct}[http://rdoc.info/gems/epitools/TypedStruct] (like Struct, but setters always coerce input to a certain type, eg: boolean, integer, etc.)
19
+ * {WM}[http://rdoc.info/gems/epitools/WM] (control/query desktop windows in X. Note: `wmctrl` must be installed)
20
+ * {Sys}[http://rdoc.info/gems/epitools/Sys] (system tools -- determine operating system, list processes, view network statistics, etc.)
21
+ * {Term}[http://rdoc.info/gems/epitools/Term] (a toolbox for making terminal-based scripts -- get terminal size, create tables, etc.)
22
+ * {Iter}[http://rdoc.info/gems/epitools/Iter] (a "stable iterator" -- lets you write algorithms that modify the array as you're iterating; good for clustering.)
23
+ * {Rash}[http://rdoc.info/gems/epitools/Rash] (a hash which can have Regexps as keys, so that many input keys can map to a single value.)
24
+ * {Progressbar}[http://rdoc.info/gems/epitools/Progressbar] (better than the progressbar gem)
25
+ * {MimeMagic}[http://rdoc.info/gems/epitools/MimeMagic] (a port of the Unix `file` utility for automatically recognizing files based on their contents; faster than running `file` on every file if you have to process large batches of files. This is originally from the mimemagic gem by {Daniel Mendler}[https://github.com/minad], and has been slightly modified and enhanced.)
26
26
 
27
27
  == Installing
28
28
 
@@ -32,7 +32,7 @@ Extras:
32
32
 
33
33
  This is basically a collection of enhancements to the ruby base types (Hash, Array,
34
34
  Enumerable, etc.). To learn how it works, read the specs in spec/*.rb,
35
- or check out the rdoc: http://rdoc.info/github/epitron/epitools/master/frames
35
+ or check out the rdoc: http://rdoc.info/gems/epitools/frames
36
36
 
37
37
  == Copyright
38
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.75
1
+ 0.5.77
@@ -19,7 +19,7 @@ autoload :Benchmark, 'benchmark'
19
19
  autoload :Tracer, 'tracer'
20
20
  autoload :CSV, 'csv'
21
21
  autoload :Shellwords, 'shellwords'
22
- autoload :Matrix, 'epitools/core_ext/matrix'
22
+ autoload :SDBM, 'sdbm'
23
23
 
24
24
  module Digest
25
25
  autoload :SHA1, 'digest/sha1'
@@ -59,6 +59,7 @@ autoload :Iter, 'epitools/iter'
59
59
  autoload :WM, 'epitools/wm'
60
60
  autoload :TypedStruct, 'epitools/typed_struct'
61
61
  autoload :Sys, 'epitools/sys'
62
+ autoload :Matrix, 'epitools/core_ext/matrix'
62
63
 
63
64
 
64
65
  ## Gems (common)
@@ -121,7 +121,7 @@ module Enumerable
121
121
  end
122
122
 
123
123
  #
124
- # Split the array into chunks, cutting between the matched element and the previous element.
124
+ # Split the array into chunks, cutting before each matched element.
125
125
  #
126
126
  # Example:
127
127
  # [1,2,3,4].split_before{|e| e == 3 } #=> [ [1,2], [3,4] ]
@@ -131,6 +131,33 @@ module Enumerable
131
131
  split_at(matcher, options, &block)
132
132
  end
133
133
 
134
+ #
135
+ # Split the array into chunks, cutting between two elements.
136
+ #
137
+ # Example:
138
+ # [1,1,2,2].split_between{|a,b| a != b } #=> [ [1,1], [2,2] ]
139
+ #
140
+ def split_between(&block)
141
+ Enumerator.new do |yielder|
142
+ current = []
143
+ last = nil
144
+
145
+ each_cons(2) do |a,b|
146
+ current << a
147
+ if yield(a,b)
148
+ yielder << current
149
+ current = []
150
+ end
151
+ last = b
152
+ end
153
+
154
+ current << last unless last.nil?
155
+ yielder << current
156
+ end
157
+ end
158
+
159
+ alias_method :cut_between, :split_between
160
+
134
161
  #
135
162
  # Sum the elements
136
163
  #
data/lib/epitools/path.rb CHANGED
@@ -132,6 +132,10 @@ class Path
132
132
  @ext = other.ext && other.ext.dup
133
133
  end
134
134
 
135
+ def self.escape(str)
136
+ Shellwords.escape(str)
137
+ end
138
+
135
139
  def self.glob(str, hints={})
136
140
  Dir[str].map { |entry| new(entry, hints) }
137
141
  end
@@ -149,12 +153,12 @@ class Path
149
153
  Path::JS.new(path)
150
154
 
151
155
  else
152
- # todo: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
156
+ # TODO: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
153
157
  path = Path.expand_path(path)
154
- if path =~ /(^|[^\\])[\?\*\{\}]/ # contains unescaped glob chars?
155
- glob(path)
156
- else
158
+ unless path =~ /(^|[^\\])[\?\*\{\}]/ # contains unescaped glob chars?
157
159
  new(path)
160
+ else
161
+ glob(path)
158
162
  end
159
163
 
160
164
  end
@@ -321,7 +325,9 @@ class Path
321
325
  end
322
326
  end
323
327
 
324
- alias_method :name, :filename
328
+ def name
329
+ filename || "#{dirs.last}/"
330
+ end
325
331
 
326
332
  def exts
327
333
  extensions = basename.split('.')[1..-1]
@@ -444,12 +450,19 @@ class Path
444
450
 
445
451
  include Comparable
446
452
 
453
+ #
454
+ # An array of attributes which will be used sort paths (case insensitive, directories come first)
455
+ #
456
+ def sort_attrs
457
+ [filename ? 1 : 0, path.downcase]
458
+ end
459
+
447
460
  def <=>(other)
448
461
  case other
449
462
  when Path
450
- self.path <=> other.path
463
+ sort_attrs <=> other.sort_attrs
451
464
  when String
452
- self.path == other
465
+ path <=> other
453
466
  else
454
467
  raise "Invalid comparison: Path to #{other.class}"
455
468
  end
@@ -503,7 +516,9 @@ class Path
503
516
  if line =~ /^([^=]+)=0s(.+)/
504
517
  key = $1
505
518
  value = $2.from_base64 # unpack base64 string
506
- value = value.encode("UTF-8", "UTF-8") # set string's encoding to UTF-8
519
+ # value = value.encode("UTF-8", "UTF-8") # set string's encoding to UTF-8
520
+ value = value.force_encoding("UTF-8").scrub # set string's encoding to UTF-8
521
+ # value = value.encode("UTF-8", "UTF-8") # set string's encoding to UTF-8
507
522
 
508
523
  attrs[key] = value
509
524
  end
@@ -628,11 +643,14 @@ class Path
628
643
  read.unmarshal
629
644
  end
630
645
 
631
- def ls; Path[File.join(path, "*")]; end
646
+ def ls
647
+ Dir.foreach(path).drop(2).map {|fn| Path.new(fn) }
648
+ end
632
649
 
633
650
  def ls_r(symlinks=false)
634
- glob = symlinks ? "**{,/*/**}/*" : "**/*"
635
- Path[File.join(path, glob)]
651
+ # glob = symlinks ? "**{,/*/**}/*" : "**/*"
652
+ # Path[File.join(path, glob)]
653
+ Find.find(path).drop(1).map {|fn| Path.new(fn) }
636
654
  end
637
655
  alias_method :ls_R, :ls_r
638
656
 
@@ -503,7 +503,25 @@ describe Enumerable do
503
503
 
504
504
  it "splits lazily" do
505
505
  result = "a\nb\nc\nd".each_line.split_at("b")
506
- result.is_an?(Enumerator).should == true
506
+ result.should be_an Enumerator
507
+ end
508
+
509
+ it "splits between" do
510
+ test_chunks = [
511
+ [ [1,1] ],
512
+ [ [1], [2] ],
513
+ [ [1,1], [2,2,2], [3,3,3,3] ],
514
+ [[]],
515
+ ]
516
+
517
+ test_chunks.each do |chunks|
518
+ result = chunks.flatten.split_between do |a,b|
519
+ a != b
520
+ end
521
+
522
+ result.should be_an Enumerator
523
+ result.to_a.should == chunks
524
+ end
507
525
  end
508
526
 
509
527
  it "sums" do
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.75
4
+ version: 0.5.77
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec