format_parser 0.25.5 → 0.25.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/format_parser.rb +17 -3
- data/lib/format_parser/version.rb +1 -1
- data/spec/format_parser_spec.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc915cd212f2207b6f54cc4b567ea342a0bfd76af1e5e3db23330a6cc879e27
|
4
|
+
data.tar.gz: 0a623b8303cbf40a58d348b4e1adcda2d6fc0170b411fba529f9d3ae53533282
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ed65c67f508264c0c6c12e88287266ef2bb9346c7e44934ac2e8ac97001de8f5e7f605bdd497ee6f95a45bcf4ad7f6b69021d25739e85debafaecfca76153ce
|
7
|
+
data.tar.gz: 4b250cd8f41bbba735e5d90a4a829c4fea699f04dd190a37499853ed48475aecd19f6d32360f081474355a4f5f9c562e1ca78e8c7c8aba91e5fb9e0ca4930299
|
data/CHANGELOG.md
CHANGED
data/lib/format_parser.rb
CHANGED
@@ -49,8 +49,10 @@ module FormatParser
|
|
49
49
|
parser_provided_formats = Array(formats)
|
50
50
|
parser_provided_natures = Array(natures)
|
51
51
|
PARSER_MUX.synchronize do
|
52
|
-
|
53
|
-
|
52
|
+
# It can't be a Set because the method `parsers_for` depends on the order
|
53
|
+
# that the parsers were added.
|
54
|
+
@parsers ||= []
|
55
|
+
@parsers << callable_parser unless @parsers.include?(callable_parser)
|
54
56
|
@parsers_per_nature ||= {}
|
55
57
|
parser_provided_natures.each do |provided_nature|
|
56
58
|
@parsers_per_nature[provided_nature] ||= Set.new
|
@@ -255,7 +257,19 @@ module FormatParser
|
|
255
257
|
# Order the parsers according to their priority value. The ones having a lower
|
256
258
|
# value will sort higher and will be applied sooner
|
257
259
|
parsers_in_order_of_priority = parsers.to_a.sort do |parser_a, parser_b|
|
258
|
-
@parser_priorities[parser_a]
|
260
|
+
if @parser_priorities[parser_a] != @parser_priorities[parser_b]
|
261
|
+
@parser_priorities[parser_a] <=> @parser_priorities[parser_b]
|
262
|
+
else
|
263
|
+
# Some parsers have the same priority and we want them to be always sorted
|
264
|
+
# in the same way, to not change the result of FormatParser.parse(results: :first).
|
265
|
+
# When this changes, it can generate flaky tests or event different
|
266
|
+
# results in different environments, which can be hard to understand why.
|
267
|
+
# There is also no guarantee in the order that the elements are added in
|
268
|
+
# @@parser_priorities
|
269
|
+
# So, to have always the same order, we sort by the order that the parsers
|
270
|
+
# were registered if the priorities are the same.
|
271
|
+
@parsers.index(parser_a) <=> @parsers.index(parser_b)
|
272
|
+
end
|
259
273
|
end
|
260
274
|
|
261
275
|
# If there is one parser that is more likely to match, place it first
|
data/spec/format_parser_spec.rb
CHANGED
@@ -173,6 +173,26 @@ describe FormatParser do
|
|
173
173
|
prioritized_parsers = FormatParser.parsers_for([:archive, :document, :image, :audio], [:tif, :jpg, :zip, :docx, :mp3, :aiff], 'a-file.zip')
|
174
174
|
expect(prioritized_parsers.first).to be_kind_of(FormatParser::ZIPParser)
|
175
175
|
end
|
176
|
+
|
177
|
+
it 'sorts the parsers by priority and name' do
|
178
|
+
parsers = FormatParser.parsers_for(
|
179
|
+
[:audio, :image],
|
180
|
+
[:cr2, :dpx, :fdx, :flac, :gif, :jpg, :mov, :mp4, :m4a, :mp3, :mpg, :mpeg, :ogg, :png, :tif, :wav]
|
181
|
+
)
|
182
|
+
|
183
|
+
expect(parsers.map { |parser| parser.class.name }).to eq([
|
184
|
+
'FormatParser::GIFParser',
|
185
|
+
'Class',
|
186
|
+
'FormatParser::PNGParser',
|
187
|
+
'FormatParser::CR2Parser',
|
188
|
+
'FormatParser::DPXParser',
|
189
|
+
'FormatParser::FLACParser',
|
190
|
+
'FormatParser::MP3Parser',
|
191
|
+
'FormatParser::OggParser',
|
192
|
+
'FormatParser::TIFFParser',
|
193
|
+
'FormatParser::WAVParser'
|
194
|
+
])
|
195
|
+
end
|
176
196
|
end
|
177
197
|
|
178
198
|
describe '.register_parser and .deregister_parser' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: format_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.25.
|
4
|
+
version: 0.25.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Noah Berman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-12-
|
12
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
292
292
|
- !ruby/object:Gem::Version
|
293
293
|
version: '0'
|
294
294
|
requirements: []
|
295
|
-
rubygems_version: 3.
|
295
|
+
rubygems_version: 3.1.4
|
296
296
|
signing_key:
|
297
297
|
specification_version: 4
|
298
298
|
summary: A library for efficient parsing of file metadata
|