elibri_onix 0.5.19 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/lib/elibri_onix/external_timestamp.rb +2 -2
  3. data/lib/elibri_onix/onix_3_0/audience_range.rb +4 -17
  4. data/lib/elibri_onix/onix_3_0/collection.rb +0 -0
  5. data/lib/elibri_onix/onix_3_0/contributor.rb +15 -38
  6. data/lib/elibri_onix/onix_3_0/excerpt_info.rb +8 -21
  7. data/lib/elibri_onix/onix_3_0/extent.rb +9 -24
  8. data/lib/elibri_onix/onix_3_0/file_info.rb +2 -13
  9. data/lib/elibri_onix/onix_3_0/header.rb +7 -17
  10. data/lib/elibri_onix/onix_3_0/imprint.rb +2 -18
  11. data/lib/elibri_onix/onix_3_0/language.rb +5 -22
  12. data/lib/elibri_onix/onix_3_0/measure.rb +4 -18
  13. data/lib/elibri_onix/onix_3_0/onix_message.rb +2 -17
  14. data/lib/elibri_onix/onix_3_0/price.rb +14 -25
  15. data/lib/elibri_onix/onix_3_0/price_constraint_limit.rb +22 -0
  16. data/lib/elibri_onix/onix_3_0/price_identifier.rb +18 -0
  17. data/lib/elibri_onix/onix_3_0/product.rb +62 -127
  18. data/lib/elibri_onix/onix_3_0/product_identifier.rb +6 -22
  19. data/lib/elibri_onix/onix_3_0/publisher.rb +4 -21
  20. data/lib/elibri_onix/onix_3_0/publisher_subject.rb +3 -13
  21. data/lib/elibri_onix/onix_3_0/publishing_date.rb +3 -21
  22. data/lib/elibri_onix/onix_3_0/related_product.rb +5 -24
  23. data/lib/elibri_onix/onix_3_0/sales_restriction.rb +5 -22
  24. data/lib/elibri_onix/onix_3_0/sender.rb +0 -12
  25. data/lib/elibri_onix/onix_3_0/stock_quantity_coded.rb +4 -19
  26. data/lib/elibri_onix/onix_3_0/supplier.rb +7 -25
  27. data/lib/elibri_onix/onix_3_0/supplier_identifier.rb +4 -23
  28. data/lib/elibri_onix/onix_3_0/supply_detail.rb +9 -26
  29. data/lib/elibri_onix/onix_3_0/supporting_resource.rb +7 -20
  30. data/lib/elibri_onix/onix_3_0/text_content.rb +9 -24
  31. data/lib/elibri_onix/onix_3_0/thema_subject.rb +2 -15
  32. data/lib/elibri_onix/onix_3_0/title_detail.rb +9 -28
  33. data/lib/elibri_onix/onix_3_0/title_element.rb +10 -35
  34. data/lib/elibri_onix/releases.rb +2 -2
  35. data/lib/elibri_onix/timestamp_parser.rb +12 -0
  36. data/lib/elibri_onix/version.rb +1 -1
  37. data/lib/elibri_onix.rb +4 -8
  38. data/test/elibri_audiobook_test.rb +1 -1
  39. data/test/elibri_contributors_test.rb +3 -3
  40. data/test/elibri_ebook_files_test.rb +2 -2
  41. data/test/elibri_extensions_test.rb +0 -12
  42. data/test/elibri_group_contributor_test.rb +1 -1
  43. data/test/elibri_onix_release_3_0_onix_message_test.rb +1 -6
  44. data/test/elibri_record_identifiers_test.rb +2 -2
  45. data/test/elibri_supporting_resources_test.rb +2 -2
  46. data/test/elibri_texts_test.rb +5 -5
  47. data/test/fixtures/all_possible_tags.xml +1 -18
  48. data/test/fixtures/lending_example.xml +419 -0
  49. data/test/fixtures/onix_announced_product_example.xml +1 -3
  50. data/test/fixtures/onix_audience_range_example.xml +1 -3
  51. data/test/fixtures/onix_audiobook_extent_example.xml +1 -3
  52. data/test/fixtures/onix_collective_work_example.xml +1 -3
  53. data/test/fixtures/onix_contributors_example.xml +1 -3
  54. data/test/fixtures/onix_ebook_extent_example.xml +1 -4
  55. data/test/fixtures/onix_edition_example.xml +1 -3
  56. data/test/fixtures/onix_epub_details_example.xml +5 -4
  57. data/test/fixtures/onix_languages_example.xml +1 -3
  58. data/test/fixtures/onix_measurement_example.xml +1 -3
  59. data/test/fixtures/onix_no_contributors_example.xml +1 -3
  60. data/test/fixtures/onix_out_of_print_product_example.xml +1 -3
  61. data/test/fixtures/onix_preorder_product_example.xml +1 -3
  62. data/test/fixtures/onix_product_form_example.xml +1 -4
  63. data/test/fixtures/onix_published_group_product_example.xml +1 -3
  64. data/test/fixtures/onix_published_product_example.xml +1 -3
  65. data/test/fixtures/onix_publisher_info_example.xml +1 -3
  66. data/test/fixtures/onix_record_identifiers_example.xml +1 -4
  67. data/test/fixtures/onix_related_products_example.xml +1 -3
  68. data/test/fixtures/onix_removed_elibri_extensions.xml +0 -1
  69. data/test/fixtures/onix_sale_restrictions_example.xml +1 -3
  70. data/test/fixtures/onix_series_memberships_example.xml +1 -3
  71. data/test/fixtures/onix_supporting_resources_example.xml +1 -2
  72. data/test/fixtures/onix_territorial_rights_example.xml +1 -4
  73. data/test/fixtures/onix_texts_example.xml +1 -3
  74. data/test/fixtures/onix_title_with_collection_example.xml +1 -3
  75. data/test/fixtures/onix_titles_example.xml +1 -3
  76. data/test/fixtures/onix_unlimited_book_sample_example.xml +1 -4
  77. data/test/lending_licence_test.rb +43 -0
  78. metadata +9 -20
  79. data/lib/elibri_onix/hash_id.rb +0 -37
  80. data/test/fixtures/old_dialect.xml +0 -29
  81. data/test/fixtures/onix_elibri_extensions_example.xml +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37003b2ae4622d77476776909412cc7a9d48b4e25363244a8d3c45fcd6aaffe3
4
- data.tar.gz: 65ba9e79b43513d0d26840ec1599f0f605faf66a3ec8df58882ff7a7e4e5a49c
3
+ metadata.gz: bba229e4695b80bfae5a39c57de112d2138e12929b3adea66365313fa2e8465e
4
+ data.tar.gz: 0a84191b7cd8a532a9eeeb5d2ef5ee57f79470f043cb49d0eaab36307fae9002
5
5
  SHA512:
6
- metadata.gz: a9964327c8934259778d663562bf814f39248877cf4b2eb97cdf85680d3306100664d8822ca8b754e1866b8d8db889c8ef11db4b90b97cc53562b52397b57127
7
- data.tar.gz: b10744c7de5f78ae9e7b57dd3fd835949fc8b0a5fc2c772618650e910e8e92f4cca5ac6e97e2eb77fc5c088f8c8f4e86e1f3d0a96baf674015b2404e12b5c8d2
6
+ metadata.gz: 0f25ff63e528bb3bd1cadedd36f30753562576e06c71acecf65a31e17076f0d3e294344b28bc0daa71d681e98e2bc805a931a7cb42f22f7dea6976f6cc59c414
7
+ data.tar.gz: 58d6369ddfa282f469480b3793855d3cb0a3eb47faf289b2c1a3dfc4d8cd9eeef1aadd306609996e928cf27c5140de3ffc0569f5a3fd2e6af5a39f13d945f3fb
@@ -3,7 +3,7 @@ module ExternalTimestamp
3
3
  def self.included(base)
4
4
  base.send(:attr_accessor, :datestamp_before_type_cast) #, :from => "@datestamp"
5
5
  end
6
-
6
+
7
7
  def set_datestamp(data)
8
8
  @datestamp_before_type_cast = data.attr('datestamp')
9
9
  end
@@ -15,7 +15,7 @@ module ExternalTimestamp
15
15
  h = datestamp_before_type_cast[9...11].to_i
16
16
  m = datestamp_before_type_cast[11...13].to_i
17
17
 
18
- Date.new(year, month, day) + h.hours + m.minutes
18
+ Time.new(year, month, day, h, m)
19
19
  end
20
20
 
21
21
  end
@@ -1,29 +1,16 @@
1
-
2
1
  module Elibri
3
2
  module ONIX
4
3
  module Release_3_0
5
4
 
6
5
  class AudienceRange
7
-
8
- #from ONIX documentation:
9
- #An optional and repeatable group of data elements which together describe an audience or readership range for which a product
10
- #is intended.
11
-
12
- #:nodoc:
13
- ATTRIBUTES = [
14
- :qualifier, :precision, :value
15
- ]
16
-
17
- #:nodoc:
18
- RELATIONS = []
19
-
6
+
20
7
  attr_reader :qualifier, :precision, :value, :to_xml
21
8
 
22
9
  def initialize(data)
23
10
  @old_xml = data.to_s
24
- @qualifier = data.at_css('AudienceRangeQualifier').try(:text)
25
- @precision = data.at_css('AudienceRangePrecision').try(:text)
26
- @value = data.at_css('AudienceRangeValue').try(:text).try(:to_i)
11
+ @qualifier = data.at_css('AudienceRangeQualifier')&.text
12
+ @precision = data.at_css('AudienceRangePrecision')&.text
13
+ @value = data.at_css('AudienceRangeValue')&.text&.to_i
27
14
  end
28
15
 
29
16
  end
Binary file
@@ -2,39 +2,16 @@
2
2
  module Elibri
3
3
  module ONIX
4
4
  module Release_3_0
5
-
6
5
  class Contributor
7
6
  include ExternalId
8
7
  include ExternalTimestamp
9
8
  include Inspector
10
9
 
11
- #from ONIX documentation:
12
- #Authorship and other forms of contribution are described by repeats of the <Contributor> composite,
13
- #within which the recommended form of representation of a person name is the structured data element
14
- #group consisting of Person name part 1 to Person name part 8. A single occurrence of the composite may
15
- #carry both the primary name of a contributor, and one or more alternative names,
16
- #for example if a contributor is referenced both by their real name and by a pseudonym,
17
- #or by the name given on the title page and by an authority-controlled name.
18
- #In addition, more than one representation of the same name may be sent.
19
-
20
- #:nodoc:
21
- ATTRIBUTES =
22
- [
23
- :number, :role, :person_name, :from_language, :titles_before_names, :names_before_key, :prefix_to_key,
24
- :key_names, :names_after_key, :biographical_note, :unnamed_persons, :role_name
25
- ]
26
-
27
- #:nodoc:
28
- RELATIONS =
29
- [
30
- :inspect_include_fields
31
- ]
32
-
33
10
  #:nodoc:
34
11
  attr_reader :number
35
12
 
36
13
  #:doc:
37
- #kod ONIX dla roli - np. 'A01' - autor, pełna lista pod adresem
14
+ #kod ONIX dla roli - np. 'A01' - autor, pełna lista pod adresem
38
15
  #https://github.com/elibri/elibri_onix_dict/blob/master/lib/elibri_onix_dict/onix_3_0/serialized/ProductFormCode.yml
39
16
  attr_reader :role
40
17
 
@@ -78,20 +55,20 @@ module Elibri
78
55
 
79
56
  def initialize(data)
80
57
  @to_xml = data.to_s
81
- @number = data.at_css('SequenceNumber').try(:text).try(:to_i)
82
- @role = data.at_css('ContributorRole').try(:text)
83
- @person_name = data.at_css('PersonName').try(:text)
84
- @person_name_inverted = data.at_css('PersonNameInverted').try(:text)
85
- @from_language = data.at_css('FromLanguage').try(:text)
86
- @titles_before_names = data.at_css('TitlesBeforeNames').try(:text)
87
- @names_before_key = data.at_css('NamesBeforeKey').try(:text)
88
- @prefix_to_key = data.at_css('PrefixToKey').try(:text)
89
- @key_names = data.at_css('KeyNames').try(:text)
90
- @names_after_key = data.at_css('NamesAfterKey').try(:text)
91
- @biographical_note = data.at_css('BiographicalNote').try(:text)
92
- @unnamed_persons = data.at_css('UnnamedPersons').try(:text)
93
- @corporate_name = data.at_css('CorporateName').try(:text)
94
- @corporate_name_inverted = data.at_css('CorporateNameInverted').try(:text)
58
+ @number = data.at_css('SequenceNumber')&.text&.to_i
59
+ @role = data.at_css('ContributorRole')&.text
60
+ @person_name = data.at_css('PersonName')&.text
61
+ @person_name_inverted = data.at_css('PersonNameInverted')&.text
62
+ @from_language = data.at_css('FromLanguage')&.text
63
+ @titles_before_names = data.at_css('TitlesBeforeNames')&.text
64
+ @names_before_key = data.at_css('NamesBeforeKey')&.text
65
+ @prefix_to_key = data.at_css('PrefixToKey')&.text
66
+ @key_names = data.at_css('KeyNames')&.text
67
+ @names_after_key = data.at_css('NamesAfterKey')&.text
68
+ @biographical_note = data.at_css('BiographicalNote')&.text
69
+ @unnamed_persons = data.at_css('UnnamedPersons')&.text if data.at_css('UnnamedPersons')&.text && data.at_css('UnnamedPersons')&.text.size > 0
70
+ @corporate_name = data.at_css('CorporateName')&.text
71
+ @corporate_name_inverted = data.at_css('CorporateNameInverted')&.text
95
72
  set_eid(data)
96
73
  set_datestamp(data)
97
74
  end
@@ -1,39 +1,27 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
6
-
7
4
  class ExcerptInfo
8
-
9
- #Informacja o fragmencie publikacji (e-book)
10
-
11
- ATTRIBUTES = [
12
- :file_type, :file_size, :md5, :updated_at, :link
13
- ]
14
-
15
- RELATIONS = [
16
- :inspect_include_fields
17
- ]
18
-
5
+
6
+ include TimestampParser
19
7
  attr_accessor :file_type, :file_size, :md5, :updated_at, :link, :eid, :to_xml
20
-
8
+
21
9
  def initialize(data)
22
10
  @to_xml = data.to_s
23
11
  if data.name == "excerpt"
24
12
  @file_type = data.attributes['file_type'].value
25
13
  @file_size = data.attributes['file_size'].value.to_i
26
14
  @md5 = data.attributes['md5'].value
27
- @updated_at = Time.parse(data.attributes['updated_at'].value)
15
+ @updated_at = parse_timestamp(data.attributes['updated_at'].value)
28
16
  @link = data.text
29
17
  @eid = data.attributes['id'].value.to_i
30
18
  elsif data.name == "ResourceVersion"
31
19
 
32
- last_updated_node = data.css("ContentDate").find { |date|
20
+ last_updated_node = data.css("ContentDate").find { |date|
33
21
  date.css("ContentDateRole").first.inner_text == Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED }
34
22
 
35
23
  if last_updated_node
36
- @updated_at = Time.parse(last_updated_node.css("Date").first.inner_text)
24
+ @updated_at = parse_timestamp(last_updated_node.css("Date").first.inner_text)
37
25
  end
38
26
  @link = data.css("ResourceLink").first.text
39
27
  @eid = @link.split("/")[4].to_i
@@ -45,7 +33,7 @@ module Elibri
45
33
  @md5 = feature_value
46
34
  elsif feature_type == Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::SIZE_IN_BYTES
47
35
  @file_size = feature_value.to_i
48
- end
36
+ end
49
37
  end
50
38
  else
51
39
  raise ArgumentError, "Unknow element for ExcerptInfo: #{data.name}"
@@ -55,9 +43,8 @@ module Elibri
55
43
  def inspect_include_fields
56
44
  [:link]
57
45
  end
58
-
59
- end
60
46
 
47
+ end
61
48
  end
62
49
  end
63
50
  end
@@ -1,44 +1,29 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
6
-
7
4
  class Extent
8
-
9
- #from ONIX documentation:
10
- #covers product extents, in terms of pages, running times, file sizes etc, as may be appropriate to each media type.
11
- #For products whose content is primarily readable text, it also covers illustrations and other kinds of ancillary matter such as the inclusion of a bibliography or index.
12
-
13
- ATTRIBUTES = [
14
- :type, :value, :unit, :type_name, :unit_name
15
- ]
16
-
17
- RELATIONS = [
18
- :inspect_include_fields
19
- ]
20
-
5
+
21
6
  attr_accessor :type, :value, :unit, :to_xml
22
-
7
+
23
8
  def initialize(data)
24
9
  @to_xml = data.to_s
25
- @type = data.css('ExtentType').try(:text).try(:strip)
26
- @value = data.css('ExtentValue').try(:text).try(:strip).try(:to_i)
27
- @unit = data.css('ExtentUnit').try(:text).try(:strip)
10
+ @type = data.css('ExtentType')&.text&.strip
11
+ @value = data.css('ExtentValue')&.text&.strip&.to_i
12
+ @unit = data.css('ExtentUnit')&.text&.strip
28
13
  end
29
14
 
30
15
  def type_name
31
- Elibri::ONIX::Dict::Release_3_0::ExtentType.find_by_onix_code(@type).try(:const_name).try(:downcase)
16
+ Elibri::ONIX::Dict::Release_3_0::ExtentType.find_by_onix_code(@type)&.const_name&.downcase
32
17
  end
33
-
18
+
34
19
  def unit_name
35
- Elibri::ONIX::Dict::Release_3_0::ExtentUnit.find_by_onix_code(@unit).try(:const_name).try(:downcase)
20
+ Elibri::ONIX::Dict::Release_3_0::ExtentUnit.find_by_onix_code(@unit)&.const_name&.downcase
36
21
  end
37
22
 
38
23
  def inspect_include_fields
39
24
  [:type_name, :unit_name]
40
25
  end
41
-
26
+
42
27
  end
43
28
 
44
29
  end
@@ -1,20 +1,9 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
6
-
7
4
  class FileInfo
8
5
 
9
- #Informacja o fragmencie publikacji (e-book)
10
-
11
- ATTRIBUTES = [
12
- :file_type, :file_size, :md5, :updated_at
13
- ]
14
-
15
- RELATIONS = [
16
- :inspect_include_fields
17
- ]
6
+ include TimestampParser
18
7
 
19
8
  attr_accessor :file_type, :file_size, :md5, :updated_at, :eid, :to_xml
20
9
 
@@ -23,7 +12,7 @@ module Elibri
23
12
 
24
13
  data.css("ResourceFileDate").each do |date|
25
14
  if date.css("ResourceFileDateRole").first.inner_text == Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED
26
- @updated_at = Time.parse(date.css("Date").first.inner_text)
15
+ @updated_at = parse_timestamp(date.css("Date").first.inner_text)
27
16
  end
28
17
  end
29
18
 
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
@@ -7,35 +5,27 @@ module Elibri
7
5
  #Class representing ONIX header
8
6
  class Header
9
7
  include Inspector
10
-
8
+
11
9
  #date, at which message was sent
12
10
  attr_accessor :sent_date_time
13
-
11
+
14
12
  #sender of the message - Elibri::ONIX::Release_3_0::Sender
15
13
  attr_accessor :sender
16
-
14
+
17
15
  #xml representation of message header
18
16
  attr_accessor :to_xml
19
-
20
- #:nodoc:
21
- ATTRIBUTES = [
22
- :sent_date_time, :sender
23
- ]
24
-
17
+
25
18
  #:nodoc:
26
- RELATIONS = []
27
-
28
- #:nodoc:
29
19
  def inspect_include_fields
30
20
  [:sender]
31
21
  end
32
22
 
33
23
  def initialize(data)
34
24
  @to_xml = data.to_s
35
- @sent_date_time = Date.parse(data.css('SentDateTime').try(:text)) if data.css('SentDateTime')
25
+ @sent_date_time = Date.parse(data.at_css('SentDateTime').text) if data.at_css('SentDateTime')
36
26
  @sender = Sender.new(data.at_css('Sender')) if data.at_css('Sender')
37
- end
38
-
27
+ end
28
+
39
29
  end
40
30
 
41
31
  end
@@ -1,32 +1,16 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
6
-
7
4
  class Imprint
8
-
9
- include HashId
10
-
11
- #from ONIX documentation:
12
- #A repeatable group of data elements which together identify an imprint or brand under which the product is marketed.
13
- #The composite must carry either a name identifier or a name or both.
14
-
15
- ATTRIBUTES = [
16
- :name
17
- ]
18
-
19
- RELATIONS = []
20
5
 
21
6
  attr_accessor :name, :to_xml
22
-
7
+
23
8
  def initialize(data)
24
9
  @to_xml = data.to_s
25
- @name = data.at_css('ImprintName').try(:text)
10
+ @name = data.at_css('ImprintName')&.text
26
11
  end
27
12
 
28
13
  end
29
-
30
14
  end
31
15
  end
32
16
  end
@@ -1,29 +1,12 @@
1
-
2
-
3
1
  module Elibri
4
2
  module ONIX
5
3
  module Release_3_0
6
-
7
4
  class Language
8
5
 
9
- #from ONIX documentation:
10
- #An optional and repeatable group of data elements which together represent a language, and specify its role and,
11
- #where required, whether it is a country variant.
12
-
13
6
  include Inspector
14
7
 
15
- #:nodoc:
16
- ATTRIBUTES = [
17
- :role, :code, :role_name, :language
18
- ]
19
-
20
- #:nodoc:
21
- RELATIONS = [
22
- :inspect_include_fields
23
- ]
24
-
25
- #:doc:
26
- #kod onix roli, np. '01'
8
+ #:doc:
9
+ #kod onix roli, np. '01'
27
10
  #pełna lista ról: https://github.com/elibri/elibri_onix_dict/blob/master/lib/elibri_onix_dict/onix_3_0/serialized/LanguageRole.yml
28
11
  attr_reader :role
29
12
 
@@ -36,8 +19,8 @@ module Elibri
36
19
 
37
20
  def initialize(data)
38
21
  @to_xml = data.to_s
39
- @role = data.at_css('LanguageRole').try(:text)
40
- @code = data.at_css('LanguageCode').try(:text)
22
+ @role = data.at_css('LanguageRole')&.text
23
+ @code = data.at_css('LanguageCode')&.text
41
24
  end
42
25
 
43
26
  #określenie roli jako string, np. language_of_text
@@ -48,7 +31,7 @@ module Elibri
48
31
  #język, np. 'polski'
49
32
  def language
50
33
  Elibri::ONIX::Dict::Release_3_0::LanguageCode.find_by_onix_code(@code).name(:pl).downcase rescue nil
51
- rescue
34
+ rescue
52
35
 
53
36
  end
54
37
 
@@ -1,33 +1,20 @@
1
-
2
1
  module Elibri
3
2
  module ONIX
4
3
  module Release_3_0
5
-
6
- #klasa abstahuje parsowanie wymiarów książki.
7
4
  class Measure
8
5
 
9
- include HashId
10
-
11
- ATTRIBUTES = [
12
- :type, :measurement, :unit, :type_name
13
- ]
14
-
15
- RELATIONS = [
16
- :inspect_include_fields
17
- ]
18
-
19
6
  attr_accessor :type, :measurement, :unit, :to_xml
20
7
 
21
8
  def initialize(data)
22
9
  @to_xml = data.to_s
23
- @type = data.at_css('MeasureType').try(:text)
24
- @measurement = data.at_css('Measurement').try(:text).try(:to_i)
25
- @unit = data.at_css('MeasureUnitCode').try(:text)
10
+ @type = data.at_css('MeasureType')&.text
11
+ @measurement = data.at_css('Measurement')&.text&.to_i
12
+ @unit = data.at_css('MeasureUnitCode')&.text
26
13
 
27
14
  end
28
15
 
29
16
  def type_name
30
- Elibri::ONIX::Dict::Release_3_0::MeasureType.find_by_onix_code(@type).try(:const_name).try(:downcase)
17
+ Elibri::ONIX::Dict::Release_3_0::MeasureType.find_by_onix_code(@type)&.const_name&.downcase
31
18
  end
32
19
 
33
20
  def inspect_include_fields
@@ -35,7 +22,6 @@ module Elibri
35
22
  end
36
23
 
37
24
  end
38
-
39
25
  end
40
26
  end
41
27
  end
@@ -1,10 +1,7 @@
1
-
2
1
  module Elibri
3
2
  module ONIX
4
3
  module Release_3_0
5
-
6
- #class representing whole ONIX response from eLibri server
7
- class ONIXMessage
4
+ class ONIXMessage
8
5
  include Inspector
9
6
 
10
7
  #list of all products returned in this mnessage
@@ -13,7 +10,7 @@ module Elibri
13
10
  #xml representation of this message
14
11
  attr_accessor :to_xml
15
12
 
16
- #ONIX version number
13
+ #ONIX version number
17
14
  attr_accessor :release
18
15
 
19
16
  #returned message header - Elibri::ONIX::Release_3_0::Header
@@ -22,18 +19,6 @@ module Elibri
22
19
  # attributes of root ONIXMessage node
23
20
  attr_reader :attributes
24
21
 
25
- include HashId
26
-
27
- #:nodoc:
28
- ATTRIBUTES = [
29
- :release, :header
30
- ]
31
-
32
- #:nodoc:
33
- RELATIONS = [
34
- :products
35
- ]
36
-
37
22
  def inspect_include_fields
38
23
  [:header, :release, :products]
39
24
  end
@@ -1,40 +1,29 @@
1
-
2
-
3
-
4
-
5
1
  module Elibri
6
2
  module ONIX
7
3
  module Release_3_0
8
4
 
9
5
  class Price
10
6
 
11
- #from ONIX documentation:
12
- #A repeatable group of data elements which together specify a unit price.
13
-
14
- include HashId
15
-
16
- ATTRIBUTES = [
17
- :type, :minimum_order_quantity, :amount, :currency_code, :printed_on_product,
18
- :position_on_product, :tax_type, :tax_rate_percent, :vat
19
- ]
20
-
21
- RELATIONS = []
22
-
23
- attr_accessor :type, :minimum_order_quantity, :amount, :currency_code, :printed_on_product,
24
- :position_on_product, :tax_type, :tax_rate_percent, :to_xml
7
+ attr_accessor :type, :minimum_order_quantity, :amount, :currency_code, :printed_on_product, :price_identifier,
8
+ :position_on_product, :tax_type, :tax_rate_percent, :price_qualifier, :price_constraint_limits, :to_xml
25
9
 
26
10
  def initialize(data)
27
11
  @to_xml = data.to_s
28
- @type = data.at_css('PriceType').try(:text)
29
- @minimum_order_quantity = data.at_css('MinimumOrderQuantity').try(:text).try(:to_i)
30
- @amount = BigDecimal(data.at_css('PriceAmount').try(:text))
31
- @currency_code = data.at_css('CurrencyCode').try(:text)
32
- @printed_on_product = data.at_css('PrintedOnProduct').try(:text)
33
- @position_on_product = data.at_css('PositionOnProduct').try(:text)
12
+ @type = data.at_css('PriceType')&.text
13
+ @price_qualifier = data.at_css("PriceQualifier")&.text
14
+ @minimum_order_quantity = data.at_css('MinimumOrderQuantity')&.text&.to_i
15
+ @amount = BigDecimal(data.at_css('PriceAmount')&.text)
16
+ @currency_code = data.at_css('CurrencyCode')&.text
17
+ @printed_on_product = data.at_css('PrintedOnProduct')&.text
18
+ @position_on_product = data.at_css('PositionOnProduct')&.text
34
19
  if data.at_css('Tax')
35
- @tax_type = data.at_css('Tax').at_css('TaxType').try(:text)
20
+ @tax_type = data.at_css('Tax').at_css('TaxType')&.text
36
21
  @tax_rate_percent = data.at_css('Tax').at_css('TaxRatePercent').text.to_i if data.at_css('Tax').at_css('TaxRatePercent')
37
22
  end
23
+ @price_constraint_limits = data.css("PriceConstraintLimit").map { |pc| PriceConstraintLimit.new(pc) }
24
+ if pi = data.at_css("PriceIdentifier")
25
+ @price_identifier = PriceIdentifier.new(pi)
26
+ end
38
27
  end
39
28
 
40
29
  def printed_on_product?
@@ -0,0 +1,22 @@
1
+ module Elibri
2
+ module ONIX
3
+ module Release_3_0
4
+ class PriceConstraintLimit
5
+
6
+ attr_accessor :unit, :value, :to_xml
7
+
8
+ def initialize(data)
9
+ @to_xml = data.to_s
10
+ @unit = data.at_css('PriceConstraintUnit')&.text
11
+ @value = data.at_css("Quantity")&.text
12
+ if @unit == Elibri::ONIX::Dict::Release_3_0::PriceConstraintUnit::VALID_FROM
13
+ @value = Date.new(@value[0...4].to_i, @value[4...6].to_i, @value[6...8].to_i)
14
+ else
15
+ @value = @value.to_i
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module Elibri
2
+ module ONIX
3
+ module Release_3_0
4
+ class PriceIdentifier
5
+
6
+ attr_accessor :type, :type_name, :value, :to_xml
7
+
8
+ def initialize(data)
9
+ @to_xml = data.to_s
10
+ @type = data.at_css('PriceIDType')&.text
11
+ @type_name = data.at_css("IDTypeName")&.text
12
+ @value = data.at_css("IDValue")&.text
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end