epitools 0.4.47 → 0.4.48

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.
@@ -450,7 +450,7 @@ class Path
450
450
  def mimetype_from_ext
451
451
  MimeMagic.by_extension(ext)
452
452
  end
453
-
453
+
454
454
  #
455
455
  # Find the file's mimetype (by magic)
456
456
  #
@@ -458,11 +458,29 @@ class Path
458
458
  open { |io| MimeMagic.by_magic(io) }
459
459
  end
460
460
 
461
- def ext_by_magic
462
- # TODO: return the extension for the mime type.
463
- raise NotImplementedError
461
+ def type
462
+ @magictype ||= proc do
463
+
464
+ ext = self.ext
465
+ magic = self.magic
466
+
467
+ if !ext and magic
468
+ magic.extensions.first
469
+ elsif ext and !magic
470
+ ext
471
+ elsif !ext and !magic
472
+ :unknown
473
+ else # ext and magic
474
+ if magic.extensions.include? ext
475
+ ext
476
+ else
477
+ magic.extensions.first # just incase the extension is incorrect
478
+ end
479
+ end
480
+
481
+ end.call
464
482
  end
465
-
483
+
466
484
  ############################################################################
467
485
  ## Class Methods
468
486
 
@@ -2,17 +2,18 @@ require 'epitools'
2
2
 
3
3
  describe "autoreq" do
4
4
 
5
- it "should have MimeMagic and Units installed" do
5
+ it "should have Haml and Units installed" do
6
6
  gems = Gem.source_index.to_a.map{|name, spec| spec.name}.uniq
7
- gems.include?("mimemagic").should == true
7
+ gems.include?("haml").should == true
8
8
  gems.include?("units").should == true
9
9
  end
10
10
 
11
11
  it "autoreqs a gem" do
12
- defined?(MimeMagic).should == nil
12
+ defined?(Haml).should == nil
13
13
 
14
- autoreq :MimeMagic, 'mimemagic'
15
- lambda { MimeMagic }.should_not raise_error
14
+ autoreq :Haml, 'haml'
15
+ !!defined?(Haml).should == false
16
+ lambda { Haml }.should_not raise_error
16
17
  end
17
18
 
18
19
  it "autoreqs a regular ruby file" do
@@ -246,7 +246,11 @@ describe Path do
246
246
  end
247
247
 
248
248
  it "mimes" do
249
- Path[__FILE__].mimetype == "application/x-ruby"
249
+ Path[__FILE__].mimetype.should == "application/x-ruby"
250
+ end
251
+
252
+ it "magic types" do
253
+ Path[__FILE__].type.should == "rb"
250
254
  end
251
255
 
252
256
  it "whiches" do
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.4.47
4
+ version: 0.4.48
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-25 00:00:00.000000000 -04:00
12
+ date: 2011-06-29 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &73254740 !ruby/object:Gem::Requirement
17
+ requirement: &75924720 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.2.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *73254740
25
+ version_requirements: *75924720
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: mechanize
28
- requirement: &73253840 !ruby/object:Gem::Requirement
28
+ requirement: &75924440 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *73253840
36
+ version_requirements: *75924440
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3-ruby
39
- requirement: &73253590 !ruby/object:Gem::Requirement
39
+ requirement: &75924150 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *73253590
47
+ version_requirements: *75924150
48
48
  description: Miscellaneous utility libraries to make my life easier.
49
49
  email: chris@ill-logic.com
50
50
  executables: []
@@ -70,6 +70,8 @@ files:
70
70
  - lib/epitools/hexdump.rb
71
71
  - lib/epitools/its.rb
72
72
  - lib/epitools/lcs.rb
73
+ - lib/epitools/mimemagic.rb
74
+ - lib/epitools/mimemagic_tables.rb
73
75
  - lib/epitools/niceprint.rb
74
76
  - lib/epitools/numwords.rb
75
77
  - lib/epitools/path.rb