Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mimemagic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
mimemagic
Commits
9d678423
Commit
9d678423
authored
May 28, 2010
by
minad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version 0.1.4
parent
09cb30d1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
+24
-8
lib/mimemagic.rb
+4
-6
mimemagic.gemspec
+1
-1
test/test_mimemagic.rb
+19
-1
No files found.
lib/mimemagic.rb
View file @
9d678423
...
...
@@ -3,7 +3,7 @@ require 'stringio'
# Mime type detection
class
MimeMagic
VERSION
=
'0.1.
2
'
VERSION
=
'0.1.
4
'
attr_reader
:type
,
:mediatype
,
:subtype
...
...
@@ -23,15 +23,13 @@ class MimeMagic
# * <i>:parents</i>: String list or single string of parent mime types
# * <i>:magic</i>: Mime magic specification
# * <i>:comment</i>: Comment string
def
self
.
add
(
type
,
options
=
{}
)
def
self
.
add
(
type
,
options
)
extensions
=
[
options
[
:extensions
]].
flatten
.
compact
TYPES
[
type
]
=
[
extensions
,
[
options
[
:parents
]].
flatten
.
compact
,
options
[
:comment
]]
extensions
.
each
do
|
ext
|
EXTENSIONS
[
ext
]
=
type
end
MAGIC
.
unshift
[
type
,
[
options
[
:magic
]].
flatten
.
compact
]
if
options
[
:magic
]
extensions
.
each
{
|
ext
|
EXTENSIONS
[
ext
]
=
type
}
MAGIC
.
unshift
[
type
,
options
[
:magic
]]
if
options
[
:magic
]
end
# Returns true if type is a text format
...
...
mimemagic.gemspec
View file @
9d678423
...
...
@@ -2,7 +2,7 @@
Gem
::
Specification
.
new
do
|
s
|
s
.
name
=
%q{mimemagic}
s
.
version
=
"0.1.
2
"
s
.
version
=
"0.1.
4
"
s
.
required_rubygems_version
=
Gem
::
Requirement
.
new
(
">= 0"
)
if
s
.
respond_to?
:required_rubygems_version
=
s
.
authors
=
[
"Daniel Mendler"
]
...
...
test/test_mimemagic.rb
View file @
9d678423
...
...
@@ -28,6 +28,7 @@ describe 'MimeMagic' do
end
it
'should recognize extensions'
do
MimeMagic
.
by_extension
(
'.html'
).
to_s
.
should
.
equal
'text/html'
MimeMagic
.
by_extension
(
'html'
).
to_s
.
should
.
equal
'text/html'
MimeMagic
.
by_extension
(
:html
).
to_s
.
should
.
equal
'text/html'
MimeMagic
.
by_extension
(
'rb'
).
to_s
.
should
.
equal
'application/x-ruby'
...
...
@@ -44,11 +45,28 @@ describe 'MimeMagic' do
end
it
'should have add'
do
MimeMagic
.
add
(
'application/mimemagic-test'
,
:extensions
=>
%w(ext1 ext2)
,
:parents
=>
'application/xml'
,
:comment
=>
'Comment'
)
MimeMagic
.
add
(
'application/mimemagic-test'
,
:extensions
=>
%w(ext1 ext2)
,
:parents
=>
'application/xml'
,
:comment
=>
'Comment'
)
MimeMagic
.
by_extension
(
'ext1'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_extension
(
'ext2'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_extension
(
'ext2'
).
comment
.
should
.
equal
'Comment'
MimeMagic
.
new
(
'application/mimemagic-test'
).
extensions
.
should
.
equal
%w(ext1 ext2)
MimeMagic
.
new
(
'application/mimemagic-test'
).
should
.
be
.
child_of
'text/plain'
end
it
'should process magic'
do
MimeMagic
.
add
(
'application/mimemagic-test'
,
:magic
=>
[[
0
,
'MAGICTEST'
],
# MAGICTEST at position 0
[
1
,
'MAGICTEST'
],
# MAGICTEST at position 1
[
2
,
'MAGICTEST'
,
[[
0
,
'X'
],
[
0
,
'Y'
]]]])
# MAGICTEST at position 2 and (X at 0 or Y at 0)
MimeMagic
.
by_magic
(
'MAGICTEST'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_magic
(
'XMAGICTEST'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_magic
(
' MAGICTEST'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_magic
(
'X MAGICTEST'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_magic
(
'Y MAGICTEST'
).
to_s
.
should
.
equal
'application/mimemagic-test'
MimeMagic
.
by_magic
(
'Z MAGICTEST'
).
should
.
equal
nil
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment