ruby-nuggets 0.0.5.180 → 0.0.6.189

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.0.5
5
+ This documentation refers to ruby-nuggets version 0.0.6
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -0,0 +1,64 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of ruby-nuggets, some extensions to the Ruby programming #
5
+ # language. #
6
+ # #
7
+ # Copyright (C) 2007-2008 Jens Wille #
8
+ # #
9
+ # Authors: #
10
+ # Jens Wille <jens.wille@uni-koeln.de> #
11
+ # #
12
+ # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
+ # under the terms of the GNU General Public License as published by the Free #
14
+ # Software Foundation; either version 3 of the License, or (at your option) #
15
+ # any later version. #
16
+ # #
17
+ # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
20
+ # more details. #
21
+ # #
22
+ # You should have received a copy of the GNU General Public License along #
23
+ # with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
+ # #
25
+ ###############################################################################
26
+ #++
27
+
28
+ require 'socket'
29
+ require 'open-uri'
30
+
31
+ module URI
32
+
33
+ class << self
34
+
35
+ # call-seq:
36
+ # URI.content_type(uri) => aString or nil
37
+ #
38
+ # Return the content type of +uri+, or +nil+ if not found.
39
+ def content_type(uri)
40
+ open(uri.to_s).content_type
41
+ rescue OpenURI::HTTPError, SocketError, Errno::ENOENT, NoMethodError
42
+ nil
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ if $0 == __FILE__
50
+ %w[
51
+ http://www.google.de
52
+ htp://www.google.de
53
+ www.google.de
54
+ http://blackwinter.de/misc/
55
+ http://blackwinter.de/misc/ww.png
56
+ http://blackwinter.de/misc/suicide_is_painless.mid
57
+ http://blackwinter.de/misc/expand_macros.pl.gz
58
+ http://blackwinter.de/misc/blanc60302523.nth
59
+ http://blackwinter.de/bla
60
+ http://blawinter.de
61
+ ].each { |u|
62
+ p [u, URI.content_type(u)]
63
+ }
64
+ end
@@ -0,0 +1,93 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of ruby-nuggets, some extensions to the Ruby programming #
5
+ # language. #
6
+ # #
7
+ # Copyright (C) 2007-2008 Jens Wille #
8
+ # #
9
+ # Authors: #
10
+ # Jens Wille <jens.wille@uni-koeln.de> #
11
+ # #
12
+ # ruby-nuggets is free software; you can redistribute it and/or modify it #
13
+ # under the terms of the GNU General Public License as published by the Free #
14
+ # Software Foundation; either version 3 of the License, or (at your option) #
15
+ # any later version. #
16
+ # #
17
+ # ruby-nuggets is distributed in the hope that it will be useful, but WITHOUT #
18
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
19
+ # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
20
+ # more details. #
21
+ # #
22
+ # You should have received a copy of the GNU General Public License along #
23
+ # with ruby-nuggets. If not, see <http://www.gnu.org/licenses/>. #
24
+ # #
25
+ ###############################################################################
26
+ #++
27
+
28
+ require 'rubygems'
29
+
30
+ begin
31
+ require 'filemagic/ext'
32
+ rescue LoadError
33
+ def File.content_type(path) # :nodoc:
34
+ nil
35
+ end
36
+ end
37
+
38
+ begin
39
+ require 'mime/types'
40
+ rescue LoadError
41
+ module MIME # :nodoc:
42
+ class Types # :nodoc:
43
+ def self.of(path)
44
+ []
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ require File.join(File.dirname(__FILE__), '..', 'uri', 'content_type')
51
+
52
+ module Util
53
+
54
+ module ContentType
55
+
56
+ extend self
57
+
58
+ # call-seq:
59
+ # ContentType.of(path) => aString or nil
60
+ #
61
+ # Get the MIME-Type of the file living at +path+. Either by looking
62
+ # directly into the file (requires FileMagic), or, assuming +path+
63
+ # might denote a URI, by asking the web server (via OpenURI), or
64
+ # finally by just looking at the file extension (requires MIME::Types).
65
+ # Returns +nil+ in case no decision could be made.
66
+ #
67
+ # NOTE: This is really only useful with the filemagic and mime-types gems
68
+ # installed.
69
+ def of(path)
70
+ File.content_type(path) || URI.content_type(path) ||
71
+ ((t = MIME::Types.of(path)).empty? ? nil : t.first.content_type)
72
+ end
73
+
74
+ end
75
+
76
+ end
77
+
78
+ # Just a short-cut to make the code read nicer...
79
+ ContentType = Util::ContentType
80
+
81
+ if $0 == __FILE__
82
+ [
83
+ __FILE__,
84
+ 'bla/blub.jpg',
85
+ 'bla/blub.blob',
86
+ 'http://www.google.de',
87
+ 'http://blackwinter.de/misc/ww.png',
88
+ 'http://blackwinter.de/misc/ww.jpg',
89
+ 'http://blackwinter.de/bla/blub.blob'
90
+ ].each { |f|
91
+ p [f, ContentType.of(f)]
92
+ }
93
+ end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 5
7
+ TINY = 6
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.180
4
+ version: 0.0.6.189
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-18 00:00:00 +01:00
12
+ date: 2008-01-25 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -45,7 +45,9 @@ files:
45
45
  - lib/nuggets/array/monotone.rb
46
46
  - lib/nuggets/array/format.rb
47
47
  - lib/nuggets/array/combination.rb
48
+ - lib/nuggets/util/content_type.rb
48
49
  - lib/nuggets/util/i18n.rb
50
+ - lib/nuggets/uri/content_type.rb
49
51
  - lib/nuggets/uri/exist.rb
50
52
  - COPYING
51
53
  - HEADER
@@ -56,15 +58,15 @@ has_rdoc: true
56
58
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
57
59
  post_install_message:
58
60
  rdoc_options:
59
- - --all
60
- - --title
61
- - ruby-nuggets Application documentation
62
61
  - --line-numbers
63
- - --main
64
- - README
65
62
  - --inline-source
66
63
  - --charset
67
64
  - UTF-8
65
+ - --main
66
+ - README
67
+ - --all
68
+ - --title
69
+ - ruby-nuggets Application documentation
68
70
  require_paths:
69
71
  - lib
70
72
  required_ruby_version: !ruby/object:Gem::Requirement