Commit 061caddb by minad

code cleanup

parent bbe2490f
...@@ -36,7 +36,7 @@ class MimeMagic ...@@ -36,7 +36,7 @@ class MimeMagic
# * <i>type</i>: The mime type to remove. All associated extensions and magic are removed too. # * <i>type</i>: The mime type to remove. All associated extensions and magic are removed too.
def self.remove(type) def self.remove(type)
EXTENSIONS.delete_if {|ext, t| t == type } EXTENSIONS.delete_if {|ext, t| t == type }
MAGIC.delete_if { |t, m| t == type } MAGIC.delete_if {|t, m| t == type }
TYPES.delete(type) TYPES.delete(type)
end end
...@@ -50,7 +50,7 @@ class MimeMagic ...@@ -50,7 +50,7 @@ class MimeMagic
# Returns true if type is child of parent type # Returns true if type is child of parent type
def child_of?(parent) def child_of?(parent)
child?(type, parent) MimeMagic.child?(type, parent)
end end
# Get string list of file extensions # Get string list of file extensions
...@@ -67,7 +67,7 @@ class MimeMagic ...@@ -67,7 +67,7 @@ class MimeMagic
def self.by_extension(ext) def self.by_extension(ext)
ext = ext.to_s.downcase ext = ext.to_s.downcase
mime = ext[0..0] == '.' ? EXTENSIONS[ext[1..-1]] : EXTENSIONS[ext] mime = ext[0..0] == '.' ? EXTENSIONS[ext[1..-1]] : EXTENSIONS[ext]
mime ? new(mime) : nil mime && new(mime)
end end
# Lookup mime type by filename # Lookup mime type by filename
...@@ -82,7 +82,7 @@ class MimeMagic ...@@ -82,7 +82,7 @@ class MimeMagic
io = StringIO.new(io.to_s, 'rb:binary') io = StringIO.new(io.to_s, 'rb:binary')
end end
mime = MAGIC.find {|type, matches| magic_match(io, matches) } mime = MAGIC.find {|type, matches| magic_match(io, matches) }
mime ? new(mime[0]) : nil mime && new(mime[0])
end end
# Return type as string # Return type as string
...@@ -97,7 +97,7 @@ class MimeMagic ...@@ -97,7 +97,7 @@ class MimeMagic
private private
def child?(child, parent) def self.child?(child, parent)
child == parent || TYPES.key?(child) && TYPES[child][1].any? {|p| child?(p, parent) } child == parent || TYPES.key?(child) && TYPES[child][1].any? {|p| child?(p, parent) }
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment