mimer 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f10fb696343140276206b40e9b9bc6252b008ee3
4
+ data.tar.gz: aa32235a752a951fb6601759f377c0cf4e9f5d97
5
+ SHA512:
6
+ metadata.gz: 4093146032596371d70722a88d1b6b99c0c8957f80fbb6cd5c325d14d78daaa5364f941b4755973ce3438ba7c5d1b803e401a97b750bdb13187179093bf30c2a
7
+ data.tar.gz: 1ecd475e36de4a385f0a5058f05b7a66c9cb50ed2f3da6f8a9a4c7266858e0ebad2f4c1af1ac412477d71b962f3328e6a19bcd001a8922c9b9016dd666ecbe62
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fd -c
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+
3
+ notifications:
4
+ email: false
5
+
6
+ rvm:
7
+ - 1.9
8
+ - 2.0
9
+ - 2.1
10
+ - ruby-head
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+
16
+ script:
17
+ - "bundle exec rake spec"
@@ -0,0 +1,25 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [Unreleased][unreleased]
6
+
7
+ ## [0.1.0] - 2015-02-17
8
+ ### Added
9
+ - Use bundler
10
+ - Support Ruby 1.9, 2.0 and 2.1
11
+ ### Changed
12
+ - Update development dependencies
13
+ - Use expect-syntax for specs
14
+
15
+ ## [0.0.2] - 2010-02-10
16
+ ### Added
17
+ - Suggest file extension for image files
18
+
19
+ ## 0.0.1 - 2009-10-12
20
+ ### Added
21
+ - Initial release
22
+
23
+ [unreleased]: https://github.com/ariejan/mimer/compare/v0.1.0...HEAD
24
+ [0.1.0]: https://github.com/ariejan/mimer/compare/v0.0.2...v0.1.0
25
+ [0.0.2]: https://github.com/ariejan/mimer/compare/v0.0.1...v0.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mimer.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mimer (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.2.0)
12
+ rspec-core (~> 3.2.0)
13
+ rspec-expectations (~> 3.2.0)
14
+ rspec-mocks (~> 3.2.0)
15
+ rspec-core (3.2.0)
16
+ rspec-support (~> 3.2.0)
17
+ rspec-expectations (3.2.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.2.0)
20
+ rspec-mocks (3.2.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.2.0)
23
+ rspec-support (3.2.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.7)
30
+ mimer!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.2)
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Ariejan de Vroom
1
+ Copyright (c) 2009-2015 Ariejan de Vroom
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,50 +1,6 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
3
2
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "mimer"
8
- gem.summary = %Q{Find the mime-type of a file using unix' `file` command.}
9
- gem.description = %Q{Find the mime-type of a file using unix' `file` command. This does not look at file extension, ever.}
10
- gem.email = "ariejan@ariejan.net"
11
- gem.homepage = "http://github.com/ariejan/mimer"
12
- gem.authors = ["Ariejan de Vroom"]
13
- gem.rubyforge_project = "mimer"
14
- gem.add_development_dependency "rspec"
15
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
- end
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
21
5
 
22
- require 'spec/rake/spectask'
23
- Spec::Rake::SpecTask.new(:spec) do |spec|
24
- spec.libs << 'lib' << 'spec'
25
- spec.spec_files = FileList['spec/**/*_spec.rb']
26
- end
27
-
28
- Spec::Rake::SpecTask.new(:rcov) do |spec|
29
- spec.libs << 'lib' << 'spec'
30
- spec.pattern = 'spec/**/*_spec.rb'
31
- spec.rcov = true
32
- end
33
-
34
- task :spec => :check_dependencies
35
-
36
- task :default => :spec
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- if File.exist?('VERSION')
41
- version = File.read('VERSION')
42
- else
43
- version = ""
44
- end
45
-
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "mimer #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
50
- end
6
+ task default: :spec
@@ -1,11 +1,11 @@
1
- # Mimer find a file's mime-type using unix' `file` command. It will never
1
+ # Mimer find a file's mime-type using unix' `file` command. It will never
2
2
  # look at a file's extension.
3
3
  #
4
4
  # Basic usage:
5
- #
5
+ #
6
6
  # mimer = Mimer.identify('/tmp/testfile')
7
7
  # => #<Mimer:0x9f @filename="/tmp/testfile", @mime_type="image/jpeg; charset=binary">
8
- #
8
+ #
9
9
  # mimer.mime_type
10
10
  # => "image/jpeg; charset=binary"
11
11
  #
@@ -16,35 +16,37 @@
16
16
  # => true
17
17
  #
18
18
  class Mimer
19
-
19
+
20
+ VERSION = "0.1.0"
21
+
20
22
  # Create a new Mimer object for the specified file.
21
23
  def self.identify(filename)
22
24
  return nil if !File.exists?(filename)
23
25
  return Mimer.new(filename)
24
26
  end
25
-
27
+
26
28
  # Find the mime type for +filename+
27
29
  def initialize(filename)
28
30
  @filename = filename
29
31
  identify
30
32
  end
31
-
33
+
32
34
  # Returns the mime-type in string form.
33
35
  def mime_type
34
36
  @mime_type
35
37
  end
36
-
38
+
37
39
  # Suggests an extention to use like .jpg or .png
38
40
  def suggested_extension
39
41
  case(mime_type)
40
- when /^image\/jpeg/ : '.jpg'
41
- when /^image\/gif/ : '.gif'
42
- when /^image\/png/ : '.png'
42
+ when /^image\/jpeg/ then '.jpg'
43
+ when /^image\/gif/ then '.gif'
44
+ when /^image\/png/ then '.png'
43
45
  else
44
46
  nil
45
47
  end
46
48
  end
47
-
49
+
48
50
  # Returns true if the file is a text file.
49
51
  def text?
50
52
  mime_type.match /^text\/.*/i
@@ -54,22 +56,22 @@ class Mimer
54
56
  def image?
55
57
  mime_type.match /^image\/.*/i
56
58
  end
57
-
59
+
58
60
  # Returns true if the file is a video file.
59
61
  def video?
60
62
  mime_type.match /^video\/.*/i
61
63
  end
62
-
64
+
63
65
  # Returns true if the file is an audio file.
64
66
  def audio?
65
67
  mime_type.match /^audio\/.*/i
66
68
  end
67
-
69
+
68
70
  private
69
-
71
+
70
72
  # Identifies the file and stores the result in +@mime_type+
71
73
  def identify
72
74
  @mime_type = `/usr/bin/env file --brief --mime #{@filename}`.strip
73
75
  end
74
-
75
- end
76
+
77
+ end
@@ -1,59 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mimer'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{mimer}
8
- s.version = "0.0.2"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mimer"
8
+ spec.version = Mimer::VERSION
9
+ spec.authors = ["Ariejan de Vroom"]
10
+ spec.email = ["ariejan@ariejan.net"]
11
+ spec.summary = %q{Find the mime-type of a file using unix' `file` command.}
12
+ spec.description = %q{Find the mime-type of a file using unix' `file` command. This does not look at file extension, ever.}
13
+ spec.homepage = "https://github.com/ariejan/mimer"
14
+ spec.license = "MIT"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ariejan de Vroom"]
12
- s.date = %q{2010-02-11}
13
- s.description = %q{Find the mime-type of a file using unix' `file` command. This does not look at file extension, ever.}
14
- s.email = %q{ariejan@ariejan.net}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/mimer.rb",
27
- "mimer.gemspec",
28
- "spec/fixtures/facepalm.jpg",
29
- "spec/fixtures/google.gif",
30
- "spec/fixtures/kirk.png",
31
- "spec/fixtures/plain.txt",
32
- "spec/mimer_spec.rb",
33
- "spec/spec_helper.rb"
34
- ]
35
- s.homepage = %q{http://github.com/ariejan/mimer}
36
- s.rdoc_options = ["--charset=UTF-8"]
37
- s.require_paths = ["lib"]
38
- s.rubyforge_project = %q{mimer}
39
- s.rubygems_version = %q{1.3.5}
40
- s.summary = %q{Find the mime-type of a file using unix' `file` command.}
41
- s.test_files = [
42
- "spec/mimer_spec.rb",
43
- "spec/spec_helper.rb"
44
- ]
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
45
20
 
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 3
49
-
50
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
- s.add_development_dependency(%q<rspec>, [">= 0"])
52
- else
53
- s.add_dependency(%q<rspec>, [">= 0"])
54
- end
55
- else
56
- s.add_dependency(%q<rspec>, [">= 0"])
57
- end
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
58
24
  end
59
-
@@ -1,64 +1,64 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Mimer" do
4
-
4
+
5
5
  it "should create a new Mimer instance with identify" do
6
6
  m = Mimer.identify(fixture_path('plain.txt'))
7
-
8
- m.should_not be_nil
9
- m.should be_a(Mimer)
7
+
8
+ expect(m).not_to be_nil
9
+ expect(m).to be_a(Mimer)
10
10
  end
11
-
11
+
12
12
  it "should return nil if the file cannot be found" do
13
13
  m = Mimer.identify(fixture_path('does_not.exist'))
14
-
15
- m.should be_nil
14
+
15
+ expect(m).to be_nil
16
16
  end
17
-
17
+
18
18
  describe "text" do
19
-
19
+
20
20
  before(:each) do
21
21
  @mimer = Mimer.identify(fixture_path('plain.txt'))
22
22
  end
23
-
23
+
24
24
  it "should identify mime correctly" do
25
- @mimer.mime_type.should match(/text\/plain/)
25
+ expect(@mimer.mime_type).to match(/text\/plain/)
26
26
  end
27
-
27
+
28
28
  it "should find this text" do
29
- @mimer.should be_text
29
+ expect(@mimer).to be_text
30
30
  end
31
31
  end
32
-
32
+
33
33
  describe "image extensions" do
34
34
  it "should work for jpeg" do
35
35
  mimer = Mimer.identify(fixture_path('facepalm.jpg'))
36
- mimer.suggested_extension.should eql(".jpg")
36
+ expect(mimer.suggested_extension).to eq(".jpg")
37
37
  end
38
-
38
+
39
39
  it "should work for gif" do
40
40
  mimer = Mimer.identify(fixture_path('google.gif'))
41
- mimer.suggested_extension.should eql(".gif")
41
+ expect(mimer.suggested_extension).to eq(".gif")
42
42
  end
43
-
43
+
44
44
  it "should work for png" do
45
45
  mimer = Mimer.identify(fixture_path('kirk.png'))
46
- mimer.suggested_extension.should eql(".png")
46
+ expect(mimer.suggested_extension).to eq(".png")
47
47
  end
48
48
  end
49
-
49
+
50
50
  describe "image" do
51
-
51
+
52
52
  before(:each) do
53
53
  @mimer = Mimer.identify(fixture_path('facepalm.jpg'))
54
54
  end
55
-
55
+
56
56
  it "should identify mime correctly" do
57
- @mimer.mime_type.should match(/image\/jpeg/)
57
+ expect(@mimer.mime_type).to match(/image\/jpeg/)
58
58
  end
59
-
59
+
60
60
  it "should find this image" do
61
- @mimer.should be_image
61
+ expect(@mimer).to be_image
62
62
  end
63
- end
63
+ end
64
64
  end
@@ -1,14 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'mimer'
4
- require 'spec'
5
- require 'spec/autorun'
6
-
7
- Spec::Runner.configure do |config|
8
-
9
- end
4
+ require 'rspec'
10
5
 
11
6
  # Get a filename to a fixture file
12
7
  def fixture_path(filename)
13
8
  File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
14
- end
9
+ end
metadata CHANGED
@@ -1,39 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: mimer
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Ariejan de Vroom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2010-02-11 00:00:00 +01:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
16
42
  name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
17
48
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- description: Find the mime-type of a file using unix' `file` command. This does not look at file extension, ever.
26
- email: ariejan@ariejan.net
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: Find the mime-type of a file using unix' `file` command. This does not
56
+ look at file extension, ever.
57
+ email:
58
+ - ariejan@ariejan.net
27
59
  executables: []
28
-
29
60
  extensions: []
30
-
31
- extra_rdoc_files:
32
- - LICENSE
33
- - README.rdoc
34
- files:
35
- - .document
36
- - .gitignore
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".document"
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - CHANGELOG.md
68
+ - Gemfile
69
+ - Gemfile.lock
37
70
  - LICENSE
38
71
  - README.rdoc
39
72
  - Rakefile
@@ -46,34 +79,34 @@ files:
46
79
  - spec/fixtures/plain.txt
47
80
  - spec/mimer_spec.rb
48
81
  - spec/spec_helper.rb
49
- has_rdoc: true
50
- homepage: http://github.com/ariejan/mimer
51
- licenses: []
52
-
82
+ homepage: https://github.com/ariejan/mimer
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
53
86
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
56
- require_paths:
87
+ rdoc_options: []
88
+ require_paths:
57
89
  - lib
58
- required_ruby_version: !ruby/object:Gem::Requirement
59
- requirements:
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
60
92
  - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- version:
64
- required_rubygems_version: !ruby/object:Gem::Requirement
65
- requirements:
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
66
97
  - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
69
- version:
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
70
100
  requirements: []
71
-
72
- rubyforge_project: mimer
73
- rubygems_version: 1.3.5
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.5
74
103
  signing_key:
75
- specification_version: 3
104
+ specification_version: 4
76
105
  summary: Find the mime-type of a file using unix' `file` command.
77
- test_files:
106
+ test_files:
107
+ - spec/fixtures/facepalm.jpg
108
+ - spec/fixtures/google.gif
109
+ - spec/fixtures/kirk.png
110
+ - spec/fixtures/plain.txt
78
111
  - spec/mimer_spec.rb
79
112
  - spec/spec_helper.rb