elibri_onix 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'roxml', '>= 3.1.5'
3
+ gem 'roxml', '= 3.1.6'
4
4
  gem 'i18n'
5
5
  gem 'activesupport', '>= 3.1.0'
6
6
 
@@ -45,4 +45,4 @@ DEPENDENCIES
45
45
  mocha
46
46
  pry
47
47
  rcov
48
- roxml (>= 3.1.5)
48
+ roxml (= 3.1.6)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{elibri_onix}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcin Urbanski"]
12
- s.date = %q{2011-10-06}
12
+ s.date = %q{2011-10-07}
13
13
  s.description = %q{EDItEUR ONIX format subset implementation used in Elibri publication system}
14
14
  s.email = %q{marcin@urbanski.vdl.pl}
15
15
  s.extra_rdoc_files = [
@@ -57,6 +57,7 @@ Gem::Specification.new do |s|
57
57
  "test/elibri_onix_release_3_0_onix_message_test.rb",
58
58
  "test/elibri_onix_test.rb",
59
59
  "test/fixtures/all_possible_tags.xml",
60
+ "test/fixtures/old_dialect.xml",
60
61
  "test/helper.rb"
61
62
  ]
62
63
  s.homepage = %q{http://github.com/elibri/elibri_onix}
@@ -69,7 +70,7 @@ Gem::Specification.new do |s|
69
70
  s.specification_version = 3
70
71
 
71
72
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
- s.add_runtime_dependency(%q<roxml>, [">= 3.1.5"])
73
+ s.add_runtime_dependency(%q<roxml>, ["= 3.1.6"])
73
74
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
74
75
  s.add_runtime_dependency(%q<activesupport>, [">= 3.1.0"])
75
76
  s.add_development_dependency(%q<pry>, [">= 0"])
@@ -79,7 +80,7 @@ Gem::Specification.new do |s|
79
80
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
80
81
  s.add_development_dependency(%q<rcov>, [">= 0"])
81
82
  else
82
- s.add_dependency(%q<roxml>, [">= 3.1.5"])
83
+ s.add_dependency(%q<roxml>, ["= 3.1.6"])
83
84
  s.add_dependency(%q<i18n>, [">= 0"])
84
85
  s.add_dependency(%q<activesupport>, [">= 3.1.0"])
85
86
  s.add_dependency(%q<pry>, [">= 0"])
@@ -90,7 +91,7 @@ Gem::Specification.new do |s|
90
91
  s.add_dependency(%q<rcov>, [">= 0"])
91
92
  end
92
93
  else
93
- s.add_dependency(%q<roxml>, [">= 3.1.5"])
94
+ s.add_dependency(%q<roxml>, ["= 3.1.6"])
94
95
  s.add_dependency(%q<i18n>, [">= 0"])
95
96
  s.add_dependency(%q<activesupport>, [">= 3.1.0"])
96
97
  s.add_dependency(%q<pry>, [">= 0"])
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'active_support/core_ext/object/with_options'
3
+ require 'active_support/core_ext/module/aliasing'
3
4
  require 'bigdecimal'
4
5
  require 'roxml'
5
6
  require 'elibri_onix/version'
@@ -8,9 +8,37 @@ module Elibri
8
8
 
9
9
  xml_name 'ONIXMessage'
10
10
  xml_accessor :release, :from => "@release"
11
+ xml_accessor :elibri_dialect, :from => "@elibri:dialect"
11
12
 
12
13
  xml_accessor :products, :as => [Product]
13
14
  xml_accessor :header, :as => Header
15
+
16
+
17
+
18
+ def self.from_xml(data, *initialization_args)
19
+ xml = XML::Node.from(data)
20
+
21
+ new(*initialization_args).tap do |inst|
22
+ inst.roxml_references = roxml_attrs.map {|attr| attr.to_ref(inst) }
23
+
24
+ inst.roxml_references.each do |ref|
25
+ value = ref.value_in(xml)
26
+ if ref.is_a? ROXML::XMLObjectRef
27
+ Array(value).each do |obj|
28
+ obj.instance_variable_set(:@elibri_dialect, inst.elibri_dialect)
29
+ end
30
+ end
31
+ inst.respond_to?(ref.opts.setter) \
32
+ ? inst.send(ref.opts.setter, value) \
33
+ : inst.instance_variable_set(ref.opts.instance_variable_name, value)
34
+ end
35
+ inst.send(:after_parse) if inst.respond_to?(:after_parse, true)
36
+ end
37
+ rescue ArgumentError => e
38
+ raise e, e.message + " for class #{self}"
39
+ end
40
+
41
+
14
42
  end
15
43
 
16
44
  end
@@ -5,16 +5,33 @@ module Elibri
5
5
 
6
6
  class Product
7
7
  include ROXML
8
+ attr_accessor :elibri_dialect
8
9
 
9
10
  xml_name 'Product'
10
11
  xml_accessor :record_reference, :from => 'RecordReference'
11
12
  xml_accessor :notification_type, :from => 'NotificationType', :as => Fixnum
12
13
  xml_accessor :deletion_text, :from => 'DeletionText'
13
14
 
14
- xml_accessor :cover_type, :from => 'elibri:CoverType'
15
- xml_accessor :cover_price, :from => 'elibri:CoverPrice', :as => BigDecimal
16
- xml_accessor :vat, :from => 'elibri:Vat', :as => Fixnum
17
- xml_accessor :pkwiu, :from => 'elibri:PKWiU'
15
+ # Load attributes specific for dialect 3.0.1
16
+ xml_accessor :cover_type_from_3_0_1, :from => 'elibri:CoverType'
17
+ xml_accessor :cover_price_from_3_0_1, :from => 'elibri:CoverPrice', :as => BigDecimal
18
+ xml_accessor :vat_from_3_0_1, :from => 'elibri:Vat', :as => Fixnum
19
+ xml_accessor :pkwiu_from_3_0_1, :from => 'elibri:PKWiU'
20
+
21
+ # Attributes in namespace elibri:* are specific for dialect >= 3.0.1.
22
+ # If dialect is less than 3.0.1, returns nil.
23
+ %w{cover_type cover_price vat pkwiu}.each do |method_name|
24
+ module_eval(<<-EVAL_END, __FILE__, __LINE__ + 1)
25
+ def #{method_name} # def vat
26
+ if @elibri_dialect.to_s >= '3.0.1' # if @elibri_dialect.to_s >= '3.0.1'
27
+ #{method_name}_from_3_0_1 # vat_from_3_0_1
28
+ else # else
29
+ nil # nil
30
+ end # end
31
+ end # end
32
+ EVAL_END
33
+ end
34
+
18
35
 
19
36
  xml_accessor :identifiers, :as => [ProductIdentifier]
20
37
  xml_accessor :related_products, :as => [RelatedProduct], :in => 'RelatedMaterial'
@@ -4,7 +4,7 @@ module Elibri
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- PATCH = 0
7
+ PATCH = 1
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
@@ -1,6 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
 
4
+
4
5
  describe Elibri::ONIX::Release_3_0::ONIXMessage do
5
6
 
6
7
 
@@ -8,6 +9,8 @@ describe Elibri::ONIX::Release_3_0::ONIXMessage do
8
9
  xml_string = File.read File.join(File.dirname(__FILE__), "..", "test", "fixtures", "all_possible_tags.xml")
9
10
 
10
11
  onix = Elibri::ONIX::Release_3_0::ONIXMessage.from_xml(xml_string)
12
+ assert_equal '3.0', onix.release
13
+ assert_equal '3.0.1', onix.elibri_dialect
11
14
  assert_equal 'Elibri.com.pl', onix.header.sender.sender_name
12
15
  assert_equal 'Tomasz Meka', onix.header.sender.contact_name
13
16
  assert_equal 'kontakt@elibri.com.pl', onix.header.sender.email_address
@@ -16,6 +19,7 @@ describe Elibri::ONIX::Release_3_0::ONIXMessage do
16
19
  assert_equal 1, onix.products.size
17
20
 
18
21
  product = onix.products.first
22
+ assert_equal '3.0.1', product.elibri_dialect
19
23
 
20
24
  assert_equal 'miękka', product.cover_type
21
25
  assert_equal 12.99, product.cover_price
@@ -171,8 +175,22 @@ describe Elibri::ONIX::Release_3_0::ONIXMessage do
171
175
  product.supply_details[1].tap do |supply_detail|
172
176
  assert_equal 'very few', supply_detail.quantity_code
173
177
  end
174
-
175
178
  end
176
179
 
177
180
 
181
+ it "should consider elibri_dialect attribute and ignore attributes unrecognized in specified dialect" do
182
+ xml_string = File.read File.join(File.dirname(__FILE__), "..", "test", "fixtures", "old_dialect.xml")
183
+
184
+ onix = Elibri::ONIX::Release_3_0::ONIXMessage.from_xml(xml_string)
185
+ assert_equal '3.0', onix.release
186
+ assert_equal '3.0.0', onix.elibri_dialect
187
+
188
+ product = onix.products.first
189
+ assert_equal '3.0.0', product.elibri_dialect
190
+ assert_nil product.cover_type
191
+ assert_nil product.cover_price
192
+ assert_nil product.vat
193
+ assert_nil product.pkwiu
194
+ end
195
+
178
196
  end
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <ONIXMessage release="3.0" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
2
+ <ONIXMessage release="3.0" elibri:dialect="3.0.1" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
3
3
  <Header>
4
4
  <Sender>
5
5
  <SenderName>Elibri.com.pl</SenderName>
@@ -0,0 +1,19 @@
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
3
+ <ONIXMessage release="3.0" elibri:dialect="3.0.0" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
4
+ <Header>
5
+ <Sender>
6
+ <SenderName>Elibri.com.pl</SenderName>
7
+ <ContactName>Tomasz Meka</ContactName>
8
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
9
+ </Sender>
10
+ <SentDateTime>20111005</SentDateTime>
11
+ </Header>
12
+ <Product>
13
+ <RecordReference>fdb8fa072be774d97a97</RecordReference>
14
+ <elibri:CoverType>miękka</elibri:CoverType>
15
+ <elibri:CoverPrice>12.99</elibri:CoverPrice>
16
+ <elibri:Vat>5</elibri:Vat>
17
+ <elibri:PKWiU>58.11.1</elibri:PKWiU>
18
+ </Product>
19
+ </ONIXMessage>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elibri_onix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcin Urbanski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-06 00:00:00 +02:00
18
+ date: 2011-10-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -23,14 +23,14 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ">="
26
+ - - "="
27
27
  - !ruby/object:Gem::Version
28
- hash: 9
28
+ hash: 15
29
29
  segments:
30
30
  - 3
31
31
  - 1
32
- - 5
33
- version: 3.1.5
32
+ - 6
33
+ version: 3.1.6
34
34
  name: roxml
35
35
  version_requirements: *id001
36
36
  prerelease: false
@@ -202,6 +202,7 @@ files:
202
202
  - test/elibri_onix_release_3_0_onix_message_test.rb
203
203
  - test/elibri_onix_test.rb
204
204
  - test/fixtures/all_possible_tags.xml
205
+ - test/fixtures/old_dialect.xml
205
206
  - test/helper.rb
206
207
  has_rdoc: true
207
208
  homepage: http://github.com/elibri/elibri_onix