format_parser 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -9
- data/lib/attributes_json.rb +6 -0
- data/lib/format_parser/version.rb +1 -1
- data/spec/attributes_json_spec.rb +23 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a00aab34ab0fd5faeec5fa6069ab81b2d066b14
|
4
|
+
data.tar.gz: 51a4617a89c10524a88879cdabe34dd4ccdb24d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9865f5245c785756a9ce84a89e2d17f2dbcf15a2172c3399d5112eb2d2f5ad613e233d641b31b47bce04d1d992a25a48d7e495b6025965e6599480c280dc9f6
|
7
|
+
data.tar.gz: 563cc7d7b3c8e6011ecc1d0dff1c245183c8d3da8a04c4669030ab009e6762183689f708f67b8b7ece4d7e2fe793f53771cf2efbcc1d186f473393bd4d76caac
|
data/README.md
CHANGED
@@ -41,17 +41,11 @@ You can also optimize the metadata extraction by providing hints to the gem:
|
|
41
41
|
FormatParser.parse(File.open("myimage", "rb"), natures: [:video, :image], formats: [:jpg, :png, :mp4], results: :all)
|
42
42
|
```
|
43
43
|
|
44
|
-
|
44
|
+
Return values of all parsers have built-in JSON serialization
|
45
45
|
|
46
46
|
```ruby
|
47
|
-
|
48
|
-
|
49
|
-
attr_accessor :number_of_bars
|
50
|
-
end
|
51
|
-
|
52
|
-
the_foo = Foo.new
|
53
|
-
the_foo.number_of_bars = 42
|
54
|
-
the_foo.as_json #=> {:number_of_bars => 42}
|
47
|
+
img_info = FormatParser.parse(File.open("myimage.jpg", "rb"))
|
48
|
+
JSON.pretty_generate(img_info) #=> ...
|
55
49
|
```
|
56
50
|
|
57
51
|
## Creating your own parsers
|
data/lib/attributes_json.rb
CHANGED
@@ -25,4 +25,10 @@ module FormatParser::AttributesJSON
|
|
25
25
|
h[reader_method_name] = value.respond_to?(:as_json) ? value.as_json : value
|
26
26
|
end
|
27
27
|
end
|
28
|
+
|
29
|
+
# Implements to_json with sane defaults - like
|
30
|
+
# support for `JSON.pretty_generate` vs. `JSON.dump`
|
31
|
+
def to_json(generator_state)
|
32
|
+
generator_state.generate(as_json)
|
33
|
+
end
|
28
34
|
end
|
@@ -26,4 +26,27 @@ describe FormatParser::AttributesJSON do
|
|
26
26
|
expect(file_related_class.ancestors).to include(FormatParser::AttributesJSON)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
it 'provides a default implementation of to_json as well' do
|
31
|
+
anon_class = Class.new do
|
32
|
+
include FormatParser::AttributesJSON
|
33
|
+
attr_accessor :foo, :bar, :baz
|
34
|
+
def nature
|
35
|
+
'good'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
instance = anon_class.new
|
39
|
+
instance.foo = 42
|
40
|
+
instance.bar = 'abcdef'
|
41
|
+
|
42
|
+
output = JSON.dump(instance)
|
43
|
+
readback = JSON.parse(output, symbolize_names: true)
|
44
|
+
|
45
|
+
expect(readback).to have_key(:nature)
|
46
|
+
|
47
|
+
# Make sure we support pretty_generate correctly
|
48
|
+
pretty_output = JSON.pretty_generate(instance)
|
49
|
+
standard_output = JSON.dump(instance)
|
50
|
+
expect(pretty_output).not_to eq(standard_output)
|
51
|
+
end
|
29
52
|
end
|
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.3.
|
4
|
+
version: 0.3.3
|
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: 2018-02-
|
12
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ks
|
@@ -230,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
230
|
version: '0'
|
231
231
|
requirements: []
|
232
232
|
rubyforge_project:
|
233
|
-
rubygems_version: 2.
|
233
|
+
rubygems_version: 2.5.2
|
234
234
|
signing_key:
|
235
235
|
specification_version: 4
|
236
236
|
summary: A library for efficient parsing of file metadata
|