epitools 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -2,6 +2,16 @@
2
2
  TODOs
3
3
  ===========================
4
4
 
5
+ + Path
6
+ |_ Fix rename/mv
7
+ |_ Full README with more real-world examples (grep scripts/)
8
+ - compare folders using Path#ls_r and Path#md5
9
+ |_ Group methods by type, like Pathname (does YARD have groups?)
10
+ |_ String#{to_p,to_P,to_Path} ?
11
+ |_ Relative Path class
12
+ |_ Class hierarchy (Path, FilePath, URLPath)
13
+ |_ (Un)Archivers (zip, rar, etc.)
14
+
5
15
  + Logger
6
16
  |_ colourized ("ramaze" has a nice style)
7
17
  |_ output to STDERR (default)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.11
1
+ 0.5.12
data/epitools.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "epitools"
8
- s.version = "0.5.11"
8
+ s.version = "0.5.12"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["epitron"]
12
- s.date = "2012-09-22"
12
+ s.date = "2012-11-07"
13
13
  s.description = "Miscellaneous utility libraries to make my life easier."
14
14
  s.email = "chris@ill-logic.com"
15
15
  s.extra_rdoc_files = [
@@ -8,6 +8,24 @@ class Numeric
8
8
  to_s.gsub(/(\d)(?=\d{3}+(?:\.|$))(\d{3}\..*)?/,'\1,\2')
9
9
  end
10
10
 
11
+ #
12
+ # Clamp the number to a specific range
13
+ #
14
+ # Examples:
15
+ # 234234234523.clamp(0..100) #=> 100
16
+ # 12.clamp(0..100) #=> 12
17
+ # -38817112.clamp(0..100) #=> 0
18
+ #
19
+ def clamp(range)
20
+ if self < range.first
21
+ range.first
22
+ elsif self > range.last
23
+ range.last
24
+ else
25
+ self
26
+ end
27
+ end
28
+
11
29
  #
12
30
  # Time methods
13
31
  #
data/lib/epitools/sys.rb CHANGED
@@ -24,12 +24,14 @@ module Sys
24
24
  case host_os
25
25
  when /darwin/
26
26
  @os = "Darwin"
27
+ when /bsd/
28
+ @os = "BSD"
27
29
  when /linux/
28
30
  @os = "Linux"
29
31
  when /mingw|mswin|cygwin/
30
32
  @os = 'Windows'
31
33
  else
32
- raise "Unknown OS: #{host_os.inspect}"
34
+ #raise "Unknown OS: #{host_os.inspect}"
33
35
  end
34
36
 
35
37
  @os
@@ -61,6 +63,13 @@ module Sys
61
63
  #
62
64
  def self.mac?; darwin?; end
63
65
 
66
+ #
67
+ # Is this BSD?
68
+ #
69
+ def self.bsd?
70
+ os == "BSD" or os == "Darwin"
71
+ end
72
+
64
73
  #-----------------------------------------------------------------------------
65
74
 
66
75
  PS_FIELD_TABLE = [
@@ -320,7 +329,7 @@ module Sys
320
329
  begin
321
330
  self.send(platform_method_name, *args)
322
331
  rescue NoMethodError
323
- raise NotImplementedError.new("#{name} is not yet supported on this platform.")
332
+ raise NotImplementedError.new("#{name} is not yet supported on #{os}.")
324
333
  end
325
334
  end
326
335
  end
@@ -351,7 +360,7 @@ module Sys
351
360
  #
352
361
  # eg: {"en0"=>"192.168.1.101"}
353
362
  #
354
- def self.interfaces_darwin
363
+ def self.interfaces_bsd
355
364
  sections = `ifconfig`.split(/^(?=[^\t])/)
356
365
  sections_with_relevant_ip = sections.select {|i| i =~ /inet/ }
357
366
 
@@ -365,6 +374,8 @@ module Sys
365
374
  device_ips
366
375
  end
367
376
 
377
+ def self.interfaces_darwin; interfaces_bsd; end
378
+
368
379
  #
369
380
  # Linux: Return a hash of (device, IP address) pairs.
370
381
  #
data/spec/sys_spec.rb CHANGED
@@ -7,12 +7,12 @@ describe Sys::ProcessInfo do
7
7
  proc { Sys.linux? }.should_not raise_error
8
8
  proc { Sys.mac? }.should_not raise_error
9
9
  proc { Sys.darwin? }.should_not raise_error
10
+ proc { Sys.bsd? }.should_not raise_error
10
11
  proc { Sys.windows? }.should_not raise_error
11
12
 
12
- %w[Linux Windows Darwin].include?(Sys.os).should == true
13
+ %w[Linux Windows Darwin BSD].include?(Sys.os).should == true
13
14
 
14
- truths = [:linux?, :mac?, :windows?].map{|sys| Sys.send(sys)}
15
- truths.count(true).should == 1
15
+ [:linux?, :mac?, :windows?, :bsd?].any?{|os| Sys.send(os)}.should == true
16
16
  end
17
17
 
18
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-22 00:00:00.000000000 Z
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec