ddex 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d0dd9e71e077ab5f968d649091b9ef8dfed3024ea3ca3393ea1f010fc622285
4
- data.tar.gz: 6f3df8009266c1879503bc5678d228068b195764ac0075cd890e9e61adf40641
3
+ metadata.gz: 565c3680449c31b958b74485d5d224c49d86ecd78a3ef2321c0ad973a9e45dcb
4
+ data.tar.gz: 6479b38c4d334b940682be3788131ddcc295fc3522a9a52c960bab109467e3aa
5
5
  SHA512:
6
- metadata.gz: 7d6d190de025c4d53254a889eedd1a43f1f54f6de15d785f2452f9300ccea16749116cc95976b418a8191a3afa0fd9e5f0243e655b9df09718cb1a71d9755119
7
- data.tar.gz: 8848ac8988e964ca89c52f1131e351312bdddbc753393df3c2d11ed88816f76c5c0f23bfa0bc167ec4ad53c13e8ceb5cb2e3b14217e40b2666b2d9a04e0d4047
6
+ metadata.gz: 17ee2748624cb79d3aac20b522b37c751d3510d2ddab4c71e1e7eae33ca9f2c89757340a6aa3b4b9944e971e4b198cba220372c36d91f107912082fc5b51d932
7
+ data.tar.gz: 4981963a5545997690d8bf313d9883308b4d41afea5013b1f5c0a713cc007644453f5f321c44a1428f2d889f3c64183b837c0bf85ceec7f28f417da1838b1423
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = DDEX
2
2
 
3
- {<img src="https://secure.travis-ci.org/sshaw/ddex.svg"/>}[http://travis-ci.org/sshaw/ddex]
3
+ {<img src="https://github.com/sshaw/ddex/workflows/CI/badge.svg"/>}[https://github.com/sshaw/ddex/actions/workflows/ci.yml]
4
4
 
5
5
  {DDEX}[http://ddex.net] metadata serialization for Ruby
6
6
 
data/lib/ddex/element.rb CHANGED
@@ -25,7 +25,7 @@ module DDEX
25
25
  #
26
26
  # === Arguments
27
27
  #
28
- # [attributes (Hash)] Values to set on the instance's attributes, a nested +Hash+ <b>will not</b> result in instantiation of child objects.
28
+ # [attributes (Hash)] Values to set on the instance's attributes, a nested +Hash+ will result in instantiation of child objects.
29
29
  #
30
30
  # === Errors
31
31
  #
@@ -40,8 +40,21 @@ module DDEX
40
40
  method = "#{name}="
41
41
  next unless attr = roxml_attributes[name] and respond_to?(method)
42
42
 
43
- value = Array(value) if !attr.sought_type.instance_of?(Symbol) && attr.array? # If it's not a ROXML directive && ...
44
- send(method, value)
43
+ if !attr.sought_type.instance_of?(Symbol) && attr.array? # If it's not a ROXML directive && ...
44
+ value = Array(value)
45
+ end
46
+
47
+ if !value.is_a?(DDEX::Element) && attr.sought_type.is_a?(Class) && attr.sought_type.ancestors.include?(DDEX::Element)
48
+ value = if attr.array? && value.is_a?(Array)
49
+ value.map { |v| v.is_a?(DDEX::Element) ? v : attr.sought_type.new(v) }
50
+ elsif !value.is_a?(Hash)
51
+ attr.sought_type.new(name => value)
52
+ else
53
+ attr.sought_type.new(value)
54
+ end
55
+ end
56
+
57
+ public_send(method, value)
45
58
  end
46
59
  end
47
60
 
data/lib/ddex/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DDEX
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.10"
5
5
  end
data/spec/element_spec.rb CHANGED
@@ -45,7 +45,7 @@ describe DDEX::Element do
45
45
  end
46
46
  end
47
47
 
48
- describe "#new" do
48
+ describe "#initialize" do
49
49
  it "sets the instance's attributes" do
50
50
  nested = parent_attr
51
51
  nested[:child] = Child.new(child_attr)
@@ -58,6 +58,22 @@ describe DDEX::Element do
58
58
  expect(parent.child).to eq nested[:child]
59
59
  expect(parent.children).to eq nested[:children]
60
60
  end
61
+
62
+ it "instantiates the object tree from a nested attribute hash" do
63
+ attributes = parent_attr.merge(:child => child_attr, :children => [ child_attr ])
64
+ parent = Parent.new(attributes)
65
+
66
+ expect(parent.name).to eq "sshaw"
67
+ expect(parent.numbers).to eq [1,2,3]
68
+
69
+ expect(parent.child).to_not be_nil
70
+ expect(parent.child.name).to eq "fofinha"
71
+ expect(parent.child.numbers).to eq [4,5,6]
72
+
73
+ expect(parent.children.size).to eq 1
74
+ expect(parent.children[0].name).to eq "fofinha"
75
+ expect(parent.children[0].numbers).to eq [4,5,6]
76
+ end
61
77
  end
62
78
 
63
79
  describe "#to_hash" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-30 00:00:00.000000000 Z
11
+ date: 2022-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -4047,62 +4047,62 @@ signing_key:
4047
4047
  specification_version: 4
4048
4048
  summary: DDEX metadata serialization
4049
4049
  test_files:
4050
- - spec/element_spec.rb
4051
- - spec/ern/341_spec.rb~
4050
+ - spec/spec_helper.rb
4052
4051
  - spec/ern/34_spec.rb~
4053
- - spec/ern/36_spec.rb~
4054
4052
  - spec/ern/v36_spec.rb~
4055
- - spec/ern/versions_spec.rb
4053
+ - spec/ern/341_spec.rb~
4054
+ - spec/ern/36_spec.rb~
4056
4055
  - spec/ern/versions_spec.rb~
4056
+ - spec/ern/versions_spec.rb
4057
+ - spec/element_spec.rb
4058
+ - spec/support/ddex_element.rb
4057
4059
  - spec/ern_spec.rb
4058
- - spec/ern_spec.rb~
4059
- - spec/fixtures/ern/312/instance1.xml
4060
- - spec/fixtures/ern/33/instance1.xml
4060
+ - spec/fixtures/ern36.xml~
4061
+ - spec/fixtures/ern/35/instance1.xml
4061
4062
  - spec/fixtures/ern/34/instance1.xml
4063
+ - spec/fixtures/ern/33/instance1.xml
4064
+ - spec/fixtures/ern/37D2/instance1.xml
4065
+ - spec/fixtures/ern/37D2/instance1.xml~
4062
4066
  - spec/fixtures/ern/341/instance1.xml
4063
- - spec/fixtures/ern/35/instance1.xml
4064
- - spec/fixtures/ern/351/instance1.xml
4065
- - spec/fixtures/ern/36/instance1.xml
4066
- - spec/fixtures/ern/37/instance1.xml
4067
- - spec/fixtures/ern/37/instance2.xml
4067
+ - spec/fixtures/ern/383/instance1.xml
4068
+ - spec/fixtures/ern/42/6 Ringtone.xml
4069
+ - spec/fixtures/ern/42/4 SimpleAudioSingle.xml
4070
+ - spec/fixtures/ern/42/1 Audio.xml~
4071
+ - spec/fixtures/ern/42/5 SimpleVideoSingle.xml
4072
+ - spec/fixtures/ern/42/5 SimpleVideoSingle.xml~
4073
+ - spec/fixtures/ern/42/7 LongformMusicalWorkVideo.xml
4074
+ - spec/fixtures/ern/42/2 Video.xml
4075
+ - spec/fixtures/ern/42/6 Ringtone.xml~
4076
+ - spec/fixtures/ern/42/8 DjMix.xml
4077
+ - spec/fixtures/ern/42/1 Audio.xml
4078
+ - spec/fixtures/ern/42/4 SimpleAudioSingle.xml~
4079
+ - spec/fixtures/ern/42/3 MixedMedia.xml
4080
+ - spec/fixtures/ern/312/instance1.xml
4068
4081
  - spec/fixtures/ern/371/instance1.xml
4069
4082
  - spec/fixtures/ern/371/instance1.xml~
4070
- - spec/fixtures/ern/37D2/instance1.xml
4071
- - spec/fixtures/ern/37D2/instance1.xml~
4072
4083
  - spec/fixtures/ern/38/instance1.xml
4073
- - spec/fixtures/ern/381/instance1.xml
4074
- - spec/fixtures/ern/383/instance1.xml
4075
- - spec/fixtures/ern/41/instance1.xml
4076
- - spec/fixtures/ern/411/1 Audio.xml
4077
- - spec/fixtures/ern/411/1 Audio.xml~
4078
- - spec/fixtures/ern/411/2 Video.xml
4079
- - spec/fixtures/ern/411/2 Video.xml~
4080
- - spec/fixtures/ern/411/3 MixedMedia.xml
4081
- - spec/fixtures/ern/411/3 MixedMedia.xml~
4084
+ - spec/fixtures/ern/36/instance1.xml
4085
+ - spec/fixtures/ern/37/instance2.xml
4086
+ - spec/fixtures/ern/37/instance1.xml
4087
+ - spec/fixtures/ern/351/instance1.xml
4088
+ - spec/fixtures/ern/411/6 Ringtone.xml
4082
4089
  - spec/fixtures/ern/411/4 SimpleAudioSingle.xml
4083
- - spec/fixtures/ern/411/4 SimpleAudioSingle.xml~
4090
+ - spec/fixtures/ern/411/8 DjMix.xml~
4091
+ - spec/fixtures/ern/411/1 Audio.xml~
4084
4092
  - spec/fixtures/ern/411/5 SimpleVideoSingle.xml
4085
4093
  - spec/fixtures/ern/411/5 SimpleVideoSingle.xml~
4086
- - spec/fixtures/ern/411/6 Ringtone.xml
4087
- - spec/fixtures/ern/411/6 Ringtone.xml~
4088
4094
  - spec/fixtures/ern/411/7 LongformMusicalWorkVideo.xml
4089
4095
  - spec/fixtures/ern/411/7 LongformMusicalWorkVideo.xml~
4090
- - spec/fixtures/ern/411/8 DjMix.xml
4091
- - spec/fixtures/ern/411/8 DjMix.xml~
4092
4096
  - spec/fixtures/ern/411/x.xml~
4093
- - spec/fixtures/ern/42/1 Audio.xml
4094
- - spec/fixtures/ern/42/1 Audio.xml~
4095
- - spec/fixtures/ern/42/2 Video.xml
4096
- - spec/fixtures/ern/42/3 MixedMedia.xml
4097
- - spec/fixtures/ern/42/4 SimpleAudioSingle.xml
4098
- - spec/fixtures/ern/42/4 SimpleAudioSingle.xml~
4099
- - spec/fixtures/ern/42/5 SimpleVideoSingle.xml
4100
- - spec/fixtures/ern/42/5 SimpleVideoSingle.xml~
4101
- - spec/fixtures/ern/42/6 Ringtone.xml
4102
- - spec/fixtures/ern/42/6 Ringtone.xml~
4103
- - spec/fixtures/ern/42/7 LongformMusicalWorkVideo.xml
4104
- - spec/fixtures/ern/42/8 DjMix.xml
4097
+ - spec/fixtures/ern/411/2 Video.xml
4098
+ - spec/fixtures/ern/411/6 Ringtone.xml~
4099
+ - spec/fixtures/ern/411/8 DjMix.xml
4100
+ - spec/fixtures/ern/411/1 Audio.xml
4101
+ - spec/fixtures/ern/411/2 Video.xml~
4102
+ - spec/fixtures/ern/411/4 SimpleAudioSingle.xml~
4103
+ - spec/fixtures/ern/411/3 MixedMedia.xml~
4104
+ - spec/fixtures/ern/411/3 MixedMedia.xml
4105
+ - spec/fixtures/ern/41/instance1.xml
4106
+ - spec/fixtures/ern/381/instance1.xml
4105
4107
  - spec/fixtures/ern36.xml
4106
- - spec/fixtures/ern36.xml~
4107
- - spec/spec_helper.rb
4108
- - spec/support/ddex_element.rb
4108
+ - spec/ern_spec.rb~