Allow selecting image type via Regexp
For example, SVG images might be of type "image/svg" or "image/svg+xml"
This commit is contained in:
parent
e1d514d905
commit
682f66f476
@ -43,7 +43,13 @@ module Manifique
|
||||
end
|
||||
|
||||
if options[:type]
|
||||
results.reject! { |r| r["type"] != options[:type] }
|
||||
if options[:type].is_a?(String)
|
||||
results.reject! { |r| r["type"] != options[:type] }
|
||||
elsif options[:type].is_a?(Regexp)
|
||||
results.reject! { |r| r["type"].match(options[:type]).nil? }
|
||||
else
|
||||
raise ArgumentError, "Type must be a string or a regular expression"
|
||||
end
|
||||
end
|
||||
|
||||
if options[:sizes]
|
||||
|
@ -68,6 +68,16 @@ RSpec.describe Manifique::Metadata do
|
||||
icon = metadata.select_icon(type: "image/png")
|
||||
expect(icon["sizes"]).to eq("512x512")
|
||||
end
|
||||
|
||||
it "matches strings exactly" do
|
||||
icon = metadata.select_icon(type: "image/svg")
|
||||
expect(icon["type"]).to eq("image/svg")
|
||||
end
|
||||
|
||||
it "works with a regex" do
|
||||
icon = metadata.select_icon(type: /image\/svg/)
|
||||
expect(icon["type"]).to eq("image/svg+xml")
|
||||
end
|
||||
end
|
||||
|
||||
describe "by size" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user