epitools 0.4.21 → 0.4.22

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.21
1
+ 0.4.22
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.4.21"
8
+ s.version = "0.4.22"
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 = %q{2011-04-05}
12
+ s.date = %q{2011-04-06}
13
13
  s.description = %q{Miscellaneous utility libraries to make my life easier.}
14
14
  s.email = %q{chris@ill-logic.com}
15
15
  s.extra_rdoc_files = [
@@ -24,6 +24,7 @@ class Path
24
24
  ## setters
25
25
 
26
26
  attr_writer :base
27
+ attr_writer :dirs
27
28
 
28
29
  def path=(newpath)
29
30
  if File.exists? newpath
@@ -33,7 +34,7 @@ class Path
33
34
  self.dir, self.filename = File.split(newpath)
34
35
  end
35
36
  else
36
- if path[-1..-1] == File::SEPARATOR
37
+ if newpath[-1..-1] == File::SEPARATOR # ends in '/'
37
38
  self.dir = newpath
38
39
  else
39
40
  self.dir, self.filename = File.split(newpath)
@@ -51,7 +52,7 @@ class Path
51
52
  @ext = nil
52
53
  @base = newfilename
53
54
  else
54
- @ext = ext
55
+ self.ext = ext
55
56
  if pos = newfilename.rindex(ext)
56
57
  @base = newfilename[0...pos]
57
58
  end
@@ -64,17 +65,19 @@ class Path
64
65
  end
65
66
 
66
67
  def ext=(newext)
67
- if newext.nil? or newext[0] == ?.
68
- @ext = newext
68
+ if newext.blank?
69
+ @ext = nil
70
+ elsif newext[0] == ?.
71
+ @ext = newext[1..-1]
69
72
  else
70
- @ext = "." + newext
73
+ @ext = newext
71
74
  end
72
75
  end
73
76
 
74
77
 
75
78
  ## getters
76
79
 
77
- # The path's directories as an array. (eg: ['usr', 'src', 'linux'])
80
+ # The directories in the path, split into an array. (eg: ['usr', 'src', 'linux'])
78
81
  attr_reader :dirs
79
82
 
80
83
  # The filename without an extension
@@ -103,7 +106,11 @@ class Path
103
106
 
104
107
  def filename
105
108
  if base
106
- base + (ext || "")
109
+ if ext
110
+ base + "." + ext
111
+ else
112
+ base
113
+ end
107
114
  else
108
115
  nil
109
116
  end
@@ -194,8 +201,9 @@ class Path
194
201
  end
195
202
 
196
203
  #
197
- # Path("/some/path") is the same as Path["/some/path"]
204
+ # Path("/some/path") is an alias for Path["/some/path"]
198
205
  #
199
206
  def Path(*args)
200
207
  Path[*args]
201
208
  end
209
+
@@ -9,7 +9,7 @@ describe Path do
9
9
  path.dirs.should == %w[ blah what.mp4 .mp3 ]
10
10
  path.dir.should == "/blah/what.mp4/.mp3"
11
11
  path.filename.should == "hello.avi"
12
- path.ext.should == ".avi"
12
+ path.ext.should == "avi"
13
13
  path.base.should == "hello"
14
14
  end
15
15
 
@@ -34,12 +34,12 @@ describe Path do
34
34
  it "replaces ext" do
35
35
  path = Path.new("/blah/what.mp4/.mp3/hello.avi")
36
36
 
37
- path.ext.should == ".avi"
38
- path.ext = ".mkv"
39
- path.ext.should == ".mkv"
37
+ path.ext.should == "avi"
38
+ path.ext = "mkv"
39
+ path.ext.should == "mkv"
40
40
 
41
41
  path.ext = "mkv"
42
- path.ext.should == ".mkv"
42
+ path.ext.should == "mkv"
43
43
  end
44
44
 
45
45
  it "replaces filename" do
@@ -117,4 +117,12 @@ describe Path do
117
117
  ( Path['/etc']/Path['passwd'] ).should_not == Path['/etc/passwd']
118
118
  end
119
119
 
120
+ it "lets you change the dirs array" do
121
+ path = Path['/spam/spam/spam/']
122
+ path.dirs.should == %w[ spam spam spam ]
123
+ path.dirs << 'humbug'
124
+ path.dir.should == '/spam/spam/spam/humbug'
125
+ path.path.should == '/spam/spam/spam/humbug/'
126
+ end
127
+
120
128
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.21
5
+ version: 0.4.22
6
6
  platform: ruby
7
7
  authors:
8
8
  - epitron
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-05 00:00:00 -04:00
13
+ date: 2011-04-06 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency