elibri_onix_generator 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bee8e6c2913882760406524f264aab619450082b
4
- data.tar.gz: 11d3128aeb22a56d762a26b357d95ee819222c58
3
+ metadata.gz: 06524624ed33e5e6ee783f5ba9a22055f3125ed2
4
+ data.tar.gz: 552cd00f2facc30203a26e0db9d71edec5728d43
5
5
  SHA512:
6
- metadata.gz: 39843eef3ea0773575da1d41f3cf4d64392a309add00200aed180566bcd9c8bb318687eb7cc3e8e312c3f692528830b40d7b08625b8cfe0a107b18d464db0534
7
- data.tar.gz: 7f9e7e479911edc7d044a0168cc49549bf79627804414c6b08407cfae3c3b0b1aafb6f386eb23a316c574e6dbb8ba49a7167ac7e28f28fb3f1fd6e2731b6dac6
6
+ metadata.gz: ed30de577ef41dcea573fd3f172865ff85d5f97703e99dd0bc39a1e6033870f9e93206df30df7affeb461797f051108bd13b2e41717c2fcbaff483a5815ea479
7
+ data.tar.gz: edc1631e8d4a3f493f890366f411776146782503ee90848ffe471f23350e6ad6ae23185765c93476602bbcc55deb3b5206c057ad6474c4c5760723657ae837ba
@@ -18,9 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
-
25
21
  s.add_runtime_dependency "builder"
22
+ s.add_runtime_dependency "elibri_onix_dict"
26
23
  end
@@ -1,58 +1,48 @@
1
1
  # encoding: UTF-8
2
2
  require "elibri_onix_generator/version"
3
3
  require 'builder'
4
+ require 'ostruct'
5
+ require 'elibri_onix_dict'
4
6
 
5
7
  module Elibri
6
8
  module ONIX
7
9
 
8
10
  module Generator
9
- extend ActiveSupport::Concern
10
11
 
11
- SHORT_TAGS = YAML::load_file(File.dirname(__FILE__) + "/xml_tags.yml")
12
12
  DOC_ORDER = ["record_identifiers", "publishing_status", "product_form", "contributors", "titles", "series_memberships", "measurement",
13
13
  "sale_restrictions", "territorial_rights", "audience_range", "publisher_info", "extent", "edition", "languages", "epub_details",
14
14
  "texts", "supporting_resources", "subjects", "elibri_extensions"]
15
- # "related_products", "supply_details"
16
15
 
17
- included do
18
- attr_reader :builder, :tags_type
16
+ DEFAULT_DIALECT = '3.0.1'
17
+
18
+ def self.included(base)
19
+ base.extend ClassMethods
19
20
  end
20
21
 
22
+
21
23
  module ClassMethods
22
24
 
23
- def tag(builder, short_tags, tag_id, *args, &block)
24
- if short_tags
25
- if SHORT_TAGS[tag_id]
26
- tag_id = SHORT_TAGS[tag_id]
27
- elsif tag_id.starts_with?("elibri")
28
- tag_id
29
- else
30
- raise "Unknow short tag for: #{tag_id}"
31
- end
32
- end
25
+ def tag(builder, tag_id, *args, &block)
33
26
  builder.__send__(tag_id, *args, &block)
34
27
  end
35
28
 
36
29
 
37
30
  def render_header(builder, options = {}, &block)
38
- options.reverse_merge!({:short_tags => false, :elibri_onix_dialect => '3.0.1'})
39
- short_tags = options[:short_tags]
40
-
41
31
  builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
42
32
  message_attributes = {:release => "3.0", :xmlns => "http://ns.editeur.org/onix/3.0/reference", "xmlns:elibri" => "http://elibri.com.pl/ns/extensions"}
43
33
  message_attributes.delete('xmlns:elibri') if options[:pure_onix]
44
34
 
45
35
  builder.ONIXMessage message_attributes do
46
36
  unless options[:pure_onix]
47
- builder.elibri :Dialect, options[:elibri_onix_dialect] # potrzebne, aby parser wiedział jak interpretować niektóre tagi
37
+ builder.elibri :Dialect, options[:elibri_onix_dialect] || DEFAULT_DIALECT # potrzebne, aby parser wiedział jak interpretować niektóre tagi
48
38
  end
49
- tag(builder, short_tags, :Header) do
50
- tag(builder, short_tags, :Sender) do
51
- tag(builder, short_tags, :SenderName, "Elibri.com.pl")
52
- tag(builder, short_tags, :ContactName, "Tomasz Meka")
53
- tag(builder, short_tags, :EmailAddress, "kontakt@elibri.com.pl")
39
+ tag(builder, :Header) do
40
+ tag(builder, :Sender) do
41
+ tag(builder, :SenderName, "Elibri.com.pl")
42
+ tag(builder, :ContactName, "Tomasz Meka")
43
+ tag(builder, :EmailAddress, "kontakt@elibri.com.pl")
54
44
  end
55
- tag(builder, short_tags, :SentDateTime, Date.today.strftime("%Y%m%d"))
45
+ tag(builder, :SentDateTime, Date.today.strftime("%Y%m%d"))
56
46
  end
57
47
  yield(builder) if block_given?
58
48
  end
@@ -120,19 +110,23 @@ module Elibri
120
110
 
121
111
 
122
112
  def initialize(products, options = {})
123
- options.reverse_merge!({
124
- :tags_type => :full,
125
- :export_headers => true,
126
- :elibri_onix_dialect => '3.0.1',
127
- :comments => false,
128
- :xml_variant => Elibri::XmlVariant::FULL_VARIANT
129
- })
113
+ options[:export_headers] = true unless options.has_key?(:export_headers)
114
+ options[:elibri_onix_dialect] = DEFAULT_DIALECT unless options.has_key?(:elibri_onix_dialect)
115
+ options[:comments] = false unless options.has_key?(:comments)
116
+ options[:xml_variant] = OpenStruct.new(blank?: false,
117
+ includes_basic_meta?: true,
118
+ includes_other_texts?: true,
119
+ includes_media_files?: true,
120
+ includes_stocks?: false) unless options.has_key?(:xml_variant)
130
121
 
131
122
  @xml_variant = options[:xml_variant]
132
- raise ":xml_variant unspecified" if @xml_variant.blank? or !@xml_variant.kind_of?(::Elibri::XmlVariant)
123
+ raise ":xml_variant unspecified" if @xml_variant.blank?
133
124
 
134
- @products = Array.wrap(products)
135
- @tags_type = ActiveSupport::StringInquirer.new(options[:tags_type].to_s)
125
+ if products.respond_to?(:to_ary)
126
+ @products = products.to_ary
127
+ else
128
+ @products = [products]
129
+ end
136
130
  @comments = options[:comments]
137
131
  @comment_kinds = options[:comment_kinds]
138
132
  @out = []
@@ -143,7 +137,7 @@ module Elibri
143
137
 
144
138
  # W testach często nie chcę żadnych nagłówków - interesuje mnie tylko tag <Product>
145
139
  if options[:export_headers]
146
- self.class.render_header(builder, :short_tags => tags_type.short?, :elibri_onix_dialect => @elibri_onix_dialect, :pure_onix => @pure_onix) do
140
+ self.class.render_header(@builder, :elibri_onix_dialect => @elibri_onix_dialect, :pure_onix => @pure_onix) do
147
141
  render_products!
148
142
  end
149
143
  else
@@ -170,6 +164,10 @@ module Elibri
170
164
  end
171
165
  end
172
166
 
167
+ def field_exists?(object, method_name)
168
+ object.respond_to?(method_name) && object.send(method_name) && object.send(method_name).size > 0
169
+ end
170
+
173
171
 
174
172
  def comment_dictionary(description, dict, options = {})
175
173
  indent = options[:indent] || 4
@@ -232,7 +230,7 @@ module Elibri
232
230
  remove_tag_if_empty!(:PublishingDetail)
233
231
 
234
232
  #P.23 - related products
235
- if product.respond_to?(:facsimiles) && product.facsimiles.present?
233
+ if field_exists?(product, :facsimiles)
236
234
  export_related_products!(product)
237
235
  end
238
236
  #P.24 - Market
@@ -253,7 +251,7 @@ module Elibri
253
251
  # Renderuj tag w XML`u za pomocą Buildera. Jeśli wybrano opcję krótkich tagów,
254
252
  # wstaw krótki tag z hasha SHORT_TAGS.
255
253
  def tag(tag_id, *args, &block)
256
- self.class.tag(builder, tags_type.short?, tag_id, *args, &block)
254
+ self.class.tag(@builder, tag_id, *args, &block)
257
255
  end
258
256
 
259
257
  def remove_tag_if_empty!(tag_name)
@@ -282,12 +280,12 @@ module Elibri
282
280
  tag(:RecordReference, product.record_reference) #doc
283
281
  comment_dictionary "Typ powiadomienia", :NotificationType, :kind => :onix_publishing_status
284
282
  tag(:NotificationType, product.notification_type.onix_code) # Notification confirmed on publication - Lista 1
285
- if product.respond_to?(:deletion_text) && product.deletion_text.present?
283
+ if field_exists?(product, :deletion_text)
286
284
  comment "Występuje tylko gdy NotificationType == #{Elibri::ONIX::Dict::Release_3_0::NotificationType::DELETE}", :kind => :onix_record_identifiers
287
285
  tag(:DeletionText, product.deletion_text)
288
286
  end
289
287
 
290
- if product.respond_to?(:isbn_value) && product.isbn_value
288
+ if field_exists?(product, :isbn_value)
291
289
  comment 'ISBN', :kind => :onix_record_identifiers
292
290
  tag(:ProductIdentifier) do
293
291
  tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::ISBN13) #lista 5
@@ -295,7 +293,7 @@ module Elibri
295
293
  end
296
294
  end
297
295
 
298
- if product.respond_to?(:ean) && product.ean.present? && product.ean != product.isbn_value
296
+ if field_exists?(product, :ean) && product.ean != product.isbn_value
299
297
  comment 'EAN-13 - gdy inny niż ISBN', :kind => :onix_record_identifiers
300
298
 
301
299
  tag(:ProductIdentifier) do
@@ -315,7 +313,7 @@ module Elibri
315
313
  if @xml_variant.includes_stocks?
316
314
  if product.respond_to?(:product_availabilities)
317
315
  product.product_availabilities.each do |pa|
318
- if pa.supplier_identifier.present?
316
+ if field_exists?(pa, :supplier_identifier)
319
317
  comment "Identyfikator dostawcy: #{pa.supplier.name}", :kind => :onix_record_identifiers
320
318
  tag(:ProductIdentifier) do
321
319
  tag(:ProductIDType, Elibri::ONIX::Dict::Release_3_0::ProductIDType::PROPRIETARY) #lista 5
@@ -371,7 +369,7 @@ module Elibri
371
369
  # Przykład użycia w pierwszym przykładzie.
372
370
  #
373
371
  def export_epub_details!(product)
374
- if product.respond_to?(:product_form_detail_onix_codes) && product.product_form_detail_onix_codes.present? #lista 175
372
+ if field_exists?(product, :product_form_detail_onix_codes) #lista 175
375
373
  comment_dictionary "Dostępne formaty produktu", :ProductFormDetail, :indent => 10, :kind => :onix_epub_details
376
374
  product.product_form_detail_onix_codes.each do |onix_code|
377
375
  tag(:ProductFormDetail, onix_code)
@@ -475,7 +473,7 @@ module Elibri
475
473
  # dodania informacji o dodrukach realizowanych pod tym samym numerem ISBN.
476
474
  #
477
475
  def export_publishing_status!(product)
478
- if product.publishing_status_onix_code.present?
476
+ if product.publishing_status_onix_code
479
477
  comment_dictionary 'Status publikacji', :PublishingStatusCode, :indent => 10, :kind => :onix_publishing_status
480
478
  tag(:PublishingStatus, product.publishing_status_onix_code) #lista 64 #TODO sprawdzić
481
479
  end
@@ -551,7 +549,7 @@ module Elibri
551
549
  # @title Wiek czytelnika
552
550
  # Zarówno wiek 'od', jak i wiek 'do' są opcjonalne.
553
551
  def export_audience_range!(product)
554
- if product.audience_age_from.present?
552
+ if product.audience_age_from
555
553
  tag(:AudienceRange) do
556
554
  comment "Ograniczenie dotyczy wieku czytelnika - zawsze #{Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE}", :kind => :onix_audience_range
557
555
  tag(:AudienceRangeQualifier, Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE)
@@ -561,7 +559,7 @@ module Elibri
561
559
  end
562
560
  end
563
561
 
564
- if product.audience_age_to.present?
562
+ if product.audience_age_to
565
563
  tag(:AudienceRange) do
566
564
  comment "Ograniczenie dotyczy wieku czytelnika - zawsze #{Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE}", :kind => :onix_audience_range
567
565
  tag(:AudienceRangeQualifier, Elibri::ONIX::Dict::Release_3_0::AudienceRangeQualifier::READING_AGE)
@@ -602,9 +600,9 @@ module Elibri
602
600
  end
603
601
  end
604
602
 
605
- if product.respond_to?(:city_of_publication) && product.city_of_publication.present?
603
+ if field_exists?(product, :city_of_publication)
606
604
  tag(:CityOfPublication, product.city_of_publication)
607
- elsif product.respond_to?(:publisher) && product.publisher.city.present?
605
+ elsif product.respond_to?(:publisher) && product.publisher.city && product.publisher.city.size > 0
608
606
  tag(:CityOfPublication, product.publisher.city)
609
607
  end
610
608
  end
@@ -727,8 +725,8 @@ module Elibri
727
725
  #
728
726
  #
729
727
  def export_contributors!(product)
730
- if product.authorship_kind.user_given?
731
- comment 'Gdy wyszczególniono autorów', :kind => :onix_contributors if product.contributors.present?
728
+ if product.authorship_kind == "user_given"
729
+ comment 'Gdy wyszczególniono autorów', :kind => :onix_contributors if product.contributors && product.contributors.size > 0
732
730
  product.contributors.each_with_index do |contributor, idx|
733
731
  options = {}
734
732
  options[:sourcename] = "contributorid:#{contributor.id}" if contributor.respond_to?(:id)
@@ -738,20 +736,21 @@ module Elibri
738
736
  comment_dictionary 'Rola autora', :ContributorRole, :indent => 10, :kind => :onix_contributors
739
737
  tag(:ContributorRole, contributor.role_onix_code) #lista 17
740
738
  comment 'Tylko w przypadku tłumaczy:', :kind => :onix_contributors
741
- tag(:FromLanguage, contributor.language_onix_code) if contributor.respond_to?(:language_onix_code) && contributor.language_onix_code.present?
742
- tag(:PersonName, contributor.generated_full_name) #zawsze jest TODO - dodać takie pole do bazy danych
743
-
744
- tag(:TitlesBeforeNames, contributor.title) if contributor.respond_to?(:title) && contributor.title.present? #tytuł
745
- tag(:NamesBeforeKey, contributor.name) if contributor.respond_to?(:name) && contributor.name.present? #imię
746
- tag(:PrefixToKey, contributor.last_name_prefix) if contributor.respond_to?(:last_name_prefix) && contributor.last_name_prefix.present? #van, von
747
- tag(:KeyNames, contributor.last_name) if contributor.respond_to?(:last_name) && contributor.last_name.present?
748
- tag(:NamesAfterKey, contributor.last_name_postfix) if contributor.respond_to?(:last_name_postfix) && contributor.last_name_postfix.present?
749
- tag(:BiographicalNote, contributor.biography.text) if contributor.respond_to?(:biography) && contributor.biography
739
+ tag(:FromLanguage, contributor.language_onix_code) if field_exists?(contributor, :language_onix_code)
740
+ tag(:PersonName, contributor.generated_full_name)
741
+ tag(:TitlesBeforeNames, contributor.title) if field_exists?(contributor, :title)
742
+ tag(:NamesBeforeKey, contributor.name) if field_exists?(contributor, :name)
743
+ tag(:PrefixToKey, contributor.last_name_prefix) if field_exists?(contributor, :last_name_prefix)
744
+ tag(:KeyNames, contributor.last_name) if field_exists?(contributor, :last_name)
745
+ tag(:NamesAfterKey, contributor.last_name_postfix) if field_exists?(contributor, :last_name_postfix)
746
+ if contributor.respond_to?(:biography) && contributor.biography && contributor.biography.text && contributor.biography.text.strip.size > 0
747
+ tag(:BiographicalNote, contributor.biography.text)
748
+ end
750
749
  end
751
750
  end
752
751
  end
753
752
 
754
- if product.authorship_kind.collective?
753
+ if product.authorship_kind == "collective"
755
754
  comment 'Gdy jest to praca zbiorowa', :kind => :onix_contributors
756
755
  tag(:Contributor) do
757
756
  comment "Autor - #{Elibri::ONIX::Dict::Release_3_0::ContributorRole::AUTHOR}", :kind => :onix_contributors
@@ -761,7 +760,7 @@ module Elibri
761
760
  end
762
761
  end
763
762
 
764
- if product.authorship_kind.no_contributor?
763
+ if product.authorship_kind === "no_contributor"
765
764
  comment 'Gdy brak autorów', :kind => :onix_contributors
766
765
  tag(:NoContributor)
767
766
  end
@@ -780,12 +779,7 @@ module Elibri
780
779
  #
781
780
  #
782
781
  def export_titles!(product)
783
- if product.title_parts.present? or (product.respond_to?(:original_title) && product.original_title.present?) or
784
- (product.respond_to?(:trade_title) && product.trade_title.present?)
785
- #comment_dictionary 'Rozróżniane typy tytułów', :TitleType, :indent => 10, :kind => :onix_titles
786
- end
787
-
788
- if product.title_parts.present?
782
+ if product.title_parts && product.title_parts.size > 0
789
783
  tag(:TitleDetail) do
790
784
  comment "Pełen tytuł produktu - #{Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE}", :kind => :onix_titles
791
785
  tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE)
@@ -797,14 +791,15 @@ module Elibri
797
791
  comment "Tytuł na poziomie kolekcji - #{Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::COLLECTION}", :kind => :onix_titles
798
792
  end
799
793
  tag(:TitleElementLevel, title_part.level) #odnosi się do tego produktu tylko
800
- tag(:PartNumber, title_part.part) if title_part.part.present?
801
- tag(:TitleText, title_part.title) if title_part.title.present?
802
- tag(:Subtitle, title_part.subtitle) if title_part.subtitle.present?
794
+ tag(:PartNumber, title_part.part) if field_exists?(title_part, :part)
795
+ tag(:TitleText, title_part.title) if field_exists?(title_part, :title)
796
+ tag(:Subtitle, title_part.subtitle) if field_exists?(title_part, :subtitle)
803
797
  end
804
798
  end
805
799
  end
806
800
  end
807
- if product.respond_to?(:original_title) && product.original_title.present?
801
+
802
+ if field_exists?(product, :original_title)
808
803
  tag(:TitleDetail) do
809
804
  comment "Tytuł w języku oryginału - #{Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE}", :kind => :onix_titles
810
805
  tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::ORIGINAL_TITLE)
@@ -815,7 +810,8 @@ module Elibri
815
810
  end
816
811
  end
817
812
  end
818
- if product.respond_to?(:trade_title) && product.trade_title.present?
813
+
814
+ if field_exists?(product, :trade_title)
819
815
  tag(:TitleDetail) do
820
816
  comment "Tytuł handlowy używany przez wydawnictwo - #{Elibri::ONIX::Dict::Release_3_0::TitleType::DISTRIBUTORS_TITLE}", :kind => :onix_titles
821
817
  tag(:TitleType, Elibri::ONIX::Dict::Release_3_0::TitleType::DISTRIBUTORS_TITLE) #tytuł produktu
@@ -832,7 +828,7 @@ module Elibri
832
828
  # @hidden_tags RecordReference NotificationType ProductIdentifier ProductComposition ProductForm TitleDetail
833
829
  # @title Opis wydania
834
830
  def export_edition!(product)
835
- if product.respond_to?(:edition_statement) && product.edition_statement.present?
831
+ if field_exists?(product, :edition_statement)
836
832
  comment 'Opis wydania', :kind => :onix_edition
837
833
  tag(:EditionStatement, product.edition_statement)
838
834
  end
@@ -844,7 +840,7 @@ module Elibri
844
840
  # Języki, w których dostępny jest produkt.
845
841
  def export_languages!(product)
846
842
  if product.respond_to?(:languages)
847
- comment_dictionary 'Rola języka', :LanguageRole, :indent => 10, :kind => :onix_languages if product.languages.present?
843
+ comment_dictionary 'Rola języka', :LanguageRole, :indent => 10, :kind => :onix_languages if product.languages.size > 0
848
844
  product.languages.each do |language|
849
845
  tag(:Language) do
850
846
  tag(:LanguageRole, language.role_onix_code) #lista 22
@@ -861,10 +857,10 @@ module Elibri
861
857
  # Biogramy autorów są udostępniane wraz z informacjami o
862
858
  # = link_to "autorach", doc_api_path("onix_contributors")
863
859
  def export_texts!(product)
864
- comment_dictionary 'Typy tekstów', :OtherTextType, :indent => 10, :kind => :onix_texts if product.other_texts.present?
860
+ comment_dictionary 'Typy tekstów', :OtherTextType, :indent => 10, :kind => :onix_texts if product.other_texts && product.other_texts.size > 0
865
861
  product.other_texts.each do |other_text|
866
862
  #jeśli jest pusty tekst, nie nadaje się do umieszczania w ONIX albo tekst dotyczy autora (type_onix_code.blank?) -> nie exportuj
867
- next if other_text.text.blank? || other_text.type_onix_code.blank? || !other_text.exportable?
863
+ next if other_text.text.nil? || other_text.text.strip.size == 0 || other_text.type_onix_code.nil? || other_text.type_onix_code.strip.size == 0 || !other_text.exportable?
868
864
 
869
865
  options = {}
870
866
  options[:sourcename] = "textid:#{other_text.id}" if other_text.respond_to?(:id)
@@ -874,7 +870,8 @@ module Elibri
874
870
  comment "Zawsze #{Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED} - Unrestricted", :kind => :onix_texts
875
871
  tag(:ContentAudience, Elibri::ONIX::Dict::Release_3_0::ContentAudience::UNRESTRICTED)
876
872
 
877
- if other_text.respond_to?(:is_a_review?) && other_text.respond_to?(:resource_link) && other_text.is_a_review? && other_text.resource_link.present?
873
+ if other_text.respond_to?(:is_a_review?) && other_text.respond_to?(:resource_link) &&
874
+ other_text.is_a_review? && other_text.resource_link && other_text.resource_link.size > 0
878
875
  text_source = {:sourcename => other_text.resource_link}
879
876
  else
880
877
  text_source = {}
@@ -884,8 +881,8 @@ module Elibri
884
881
  builder.cdata!(other_text.text)
885
882
  end
886
883
 
887
- tag(:TextAuthor, other_text.text_author) if other_text.respond_to?(:text_author) && other_text.text_author.present?
888
- tag(:SourceTitle, other_text.source_title) if other_text.respond_to?(:source_title) && other_text.source_title.present?
884
+ tag(:TextAuthor, other_text.text_author) if field_exists?(other_text, :text_author)
885
+ tag(:SourceTitle, other_text.source_title) if field_exists?(other_text, :source_title)
889
886
  end
890
887
  end
891
888
  end
@@ -937,7 +934,7 @@ module Elibri
937
934
  comment "Używamy tylko #{Elibri::ONIX::Dict::Release_3_0::CollectionType::PUBLISHER_COLLECTION} - seria wydawnictwa", :kind => :onix_series_memberships
938
935
  tag(:CollectionType, Elibri::ONIX::Dict::Release_3_0::CollectionType::PUBLISHER_COLLECTION) #lista 148
939
936
 
940
- if series_membership.respond_to?(:issn) && series_membership.issn.present?
937
+ if field_exists?(series_membership, :issn)
941
938
  comment "W przypadku prasy serializowany jest numer ISSN"
942
939
  tag(:CollectionIdentifier) do
943
940
  tag(:CollectionIDType, "02") #issn - lista 13
@@ -951,7 +948,7 @@ module Elibri
951
948
  tag(:TitleElement) do
952
949
  comment "Używamy tylko #{Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::COLLECTION}", :kind => :onix_series_memberships
953
950
  tag(:TitleElementLevel, Elibri::ONIX::Dict::Release_3_0::TitleElementLevel::COLLECTION)
954
- tag(:PartNumber, series_membership.number_within_series) if series_membership.number_within_series.present?
951
+ tag(:PartNumber, series_membership.number_within_series) if series_membership.number_within_series
955
952
  tag(:TitleText, series_membership.series_name)
956
953
  end
957
954
  end
@@ -1006,9 +1003,9 @@ module Elibri
1006
1003
  tag(:IDValue, pa.supplier.nip.gsub("-", ""))
1007
1004
  end
1008
1005
  tag(:SupplierName, pa.supplier.name)
1009
- tag(:TelephoneNumber, pa.supplier.phone) if pa.supplier.phone.present?
1010
- tag(:EmailAddress, pa.supplier.email) if pa.supplier.email.present?
1011
- if pa.supplier.website.present?
1006
+ tag(:TelephoneNumber, pa.supplier.phone) if field_exists?(pa.supplier, :phone)
1007
+ tag(:EmailAddress, pa.supplier.email) if field_exists?(pa.supplier, :email)
1008
+ if field_exists?(pa.supplier, :website)
1012
1009
  tag(:Website) do
1013
1010
  tag(:WebsiteLink, pa.supplier.website)
1014
1011
  end
@@ -1031,7 +1028,7 @@ module Elibri
1031
1028
  end
1032
1029
  end
1033
1030
  end
1034
- if product.pack_quantity.present?
1031
+ if product.pack_quantity
1035
1032
  comment 'Ile produktów dostawca umieszcza w paczce'
1036
1033
  tag(:PackQuantity, product.pack_quantity)
1037
1034
  end
@@ -1048,7 +1045,7 @@ module Elibri
1048
1045
  tag(:TaxRatePercent, price_info.vat)
1049
1046
  end
1050
1047
  tag(:CurrencyCode, price_info.currency_code)
1051
- if product.price_printed_on_product_onix_code.present?
1048
+ if product.price_printed_on_product_onix_code
1052
1049
  comment_dictionary "Cena na okładce?", :PricePrintedOnProduct, :indent => 12
1053
1050
  tag(:PrintedOnProduct, product.price_printed_on_product_onix_code) #lista 174
1054
1051
  comment 'Zawsze 00 - Unknown / unspecified'
@@ -1071,32 +1068,32 @@ module Elibri
1071
1068
  def export_elibri_extensions!(product)
1072
1069
  if @elibri_onix_dialect >= '3.0.1'
1073
1070
 
1074
- if product.cover_type
1071
+ if field_exists?(product, :cover_type)
1075
1072
  comment_dictionary "Format okładki", Product::CoverType.all.map(&:name), :indent => 10
1076
1073
  tag("elibri:CoverType", product.cover_type.name)
1077
1074
  end
1078
1075
 
1079
1076
  comment 'Cena na okładce'
1080
- tag("elibri:CoverPrice", product.price_amount) if product.price_amount.present?
1077
+ tag("elibri:CoverPrice", product.price_amount) if field_exists?(product, :price_amount)
1081
1078
  comment 'Vat w procentach'
1082
- tag("elibri:Vat", product.vat) if product.vat.present?
1083
- tag("elibri:PKWiU", product.pkwiu) if product.pkwiu.present?
1084
- tag("elibri:PDWExclusiveness", product.pdw_exclusiveness) if product.pdw_exclusiveness.present?
1085
- tag("elibri:AdditionalInfo", product.additional_info) if product.additional_info.present?
1086
- tag("elibri:preview_exists", product.preview_exists?.to_s)
1087
- if product.digital?
1079
+ tag("elibri:Vat", product.vat) if field_exists?(product, :vat)
1080
+ tag("elibri:PKWiU", product.pkwiu) if field_exists?(product, :pkwiu)
1081
+ tag("elibri:PDWExclusiveness", product.pdw_exclusiveness) if field_exists?(product, :pdw_exclusiveness)
1082
+ tag("elibri:AdditionalInfo", product.additional_info) if field_exists?(product, :additional_info)
1083
+ tag("elibri:preview_exists", product.preview_exists?.to_s) if product.respond_to?(:preview_exists?)
1084
+ if product.respond_to?(:digital?) && product.digital?
1088
1085
  if product.epub_sale_not_restricted? || product.epub_sale_restricted_to.nil?
1089
1086
  tag("elibri:SaleNotRestricted")
1090
1087
  else
1091
1088
  tag("elibri:SaleRestrictedTo", product.epub_sale_restricted_to.strftime("%Y%m%d"))
1092
1089
  end
1093
1090
  end
1094
- if product.isbn
1091
+ if product.respond_to?(:isbn) && product.isbn
1095
1092
  tag("elibri:HyphenatedISBN", product.isbn.human_value)
1096
1093
  end
1097
1094
 
1098
- if product.digital?
1099
- if product.excerpts.present?
1095
+ if product.respond_to?(:digital?) && product.digital?
1096
+ if product.excerpts.size > 0
1100
1097
  tag("elibri:excerpts") do
1101
1098
  product.excerpts.each do |excerpt|
1102
1099
  tag("elibri:excerpt", "https://www.elibri.com.pl/excerpt/#{excerpt.id}", :md5 => excerpt.file_md5, :file_size => excerpt.stored_file_size,
@@ -1104,7 +1101,7 @@ module Elibri
1104
1101
  end
1105
1102
  end
1106
1103
  end
1107
- if product.masters.present?
1104
+ if product.masters.size > 0
1108
1105
  tag("elibri:masters") do
1109
1106
  product.masters.each do |sf|
1110
1107
  tag("elibri:master", :id => sf.id, :md5 => sf.file_md5, :file_size => sf.stored_file_size,
@@ -1,3 +1,3 @@
1
1
  module ElibriOnixGenerator
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elibri_onix_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Urbański
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-16 00:00:00.000000000 Z
12
+ date: 2018-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: elibri_onix_dict
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  description: XML Generator used by Elibri gems
29
43
  email:
30
44
  - marcin@urbanski.vdl.pl
@@ -40,7 +54,6 @@ files:
40
54
  - elibri_onix_generator.gemspec
41
55
  - lib/elibri_onix_generator.rb
42
56
  - lib/elibri_onix_generator/version.rb
43
- - lib/xml_tags.yml
44
57
  homepage: ''
45
58
  licenses: []
46
59
  metadata: {}
data/lib/xml_tags.yml DELETED
@@ -1,388 +0,0 @@
1
- ---
2
- :WorkRelationCode: :x454
3
- :TaxType: :x470
4
- :ContributorDescription: :b048
5
- :Affiliation: :b046
6
- :PriceQualifier: :j261
7
- :DiscountType: :x467
8
- :ProductClassificationCode: :b275
9
- :CountryCode: :b251
10
- :AudienceRange: :audiencerange
11
- :DiscountPercent: :j267
12
- :SenderName: :x298
13
- :ReligiousText: :religioustext
14
- :ProductRelationCode: :x455
15
- :DiscountCodeTypeName: :j378
16
- :BiographicalNote: :b044
17
- :NewSupplier: :newsupplier
18
- :ThesisPresentedTo: :b369
19
- :SubjectSchemeIdentifier: :b067
20
- :ResourceVersionFeatureType: :x442
21
- :ExtentType: :b218
22
- :ComponentNumber: :b289
23
- :MarketDate: :marketdate
24
- :UnpricedItemType: :j192
25
- :SupplyDetail: :supplydetail
26
- :ScriptCode: :x420
27
- :ContentDate: :contentdate
28
- :Discount: :discount
29
- :PriceCondition: :pricecondition
30
- :ImprintIdentifier: :imprintidentifier
31
- :StudyBibleType: :b389
32
- :PublishingDateRole: :x448
33
- :PrizeCode: :g129
34
- :CopyrightOwnerIdentifier: :copyrightowneridentifier
35
- :AncillaryContentDescription: :x424
36
- :OnOrder: :j351
37
- :EpubUsageType: :x318
38
- :RegionsExcluded: :x452
39
- :ProductFormFeatureDescription: :b336
40
- :Bible: :bible
41
- :MinimumOrderQuantity: :j263
42
- :EmailAddress: :j272
43
- :TextContent: :textcontent
44
- :ResourceFeature: :resourcefeature
45
- :CollectionIdentifier: :collectionidentifier
46
- :ListName: :x432
47
- :TitlesBeforeNames: :b038
48
- :SupplierIdentifier: :supplieridentifier
49
- :SalesOutlet: :salesoutlet
50
- :FreeQuantity: :j265
51
- :ConferenceRole: :b051
52
- :YearOfAnnual: :b020
53
- :TelephoneNumber: :j270
54
- :PriceStatus: :j266
55
- :ContributorPlace: :contributorplace
56
- :AgentIdentifier: :agentidentifier
57
- :RecordReference: :a001
58
- :ProductClassificationType: :b274
59
- :PersonName: :b036
60
- :CountryOfManufacture: :x316
61
- :AudienceRangePrecision: :b075
62
- :SentDateTime: :x307
63
- :ReligiousTextFeature: :religioustextfeature
64
- :ProductSupply: :productsupply
65
- :NoCollection: :x411
66
- :DiscountCoded: :discountcoded
67
- :BookClubAdoption: :k169
68
- :ThesisType: :b368
69
- :SubjectSchemeName: :b171
70
- :ROWSalesRightsType: :x456
71
- :MarketDateRole: :j408
72
- :ExtentUnit: :b220
73
- :ComponentTypeName: :b288
74
- :Website: :website
75
- :SupportingResource: :supportingresource
76
- :Sender: :sender
77
- :PriceConditionQuantity: :priceconditionquantity
78
- :ImprintIDType: :x445
79
- :ContentDateRole: :x429
80
- :Subject: :subject
81
- :PublishingDetail: :publishingdetail
82
- :OnOrderDetail: :onorderdetail
83
- :EpubUsageUnit: :x321
84
- :PrizeCountry: :g128
85
- :CopyrightStatement: :copyrightstatement
86
- :Audience: :audience
87
- :Reissue: :reissue
88
- :ProductFormFeatureType: :b334
89
- :NameAsSubject: :nameassubject
90
- :BibleContents: :b352
91
- :TextItem: :textitem
92
- :ResourceFeatureType: :x438
93
- :LocationIdentifier: :locationidentifier
94
- :CollectionIDType: :x344
95
- :TitleText: :b203
96
- :SupplierIDType: :j345
97
- :SalesOutletIdentifier: :salesoutletidentifier
98
- :Product: :product
99
- :FromLanguage: :x412
100
- :ConferenceSponsor: :conferencesponsor
101
- :DateFormat: :j260
102
- :Territory: :territory
103
- :NumberOfCopies: :x323
104
- :PriceType: :x462
105
- :ContributorPlaceRelator: :x418
106
- :AgentIDType: :j400
107
- :RecordSourceIdentifier: :recordsourceidentifier
108
- :ProductComposition: :x314
109
- :Measurement: :c094
110
- :CountryOfPublication: :b083
111
- :AudienceRangeQualifier: :b074
112
- :PersonNameInverted: :b037
113
- :SequenceNumber: :b034
114
- :ReligiousTextFeatureCode: :b359
115
- :ProfessionalAffiliation: :professionalaffiliation
116
- :LanguageCode: :b252
117
- :NoContributor: :n339
118
- :EpubTechnicalProtection: :x317
119
- :CBO: :j375
120
- :ThesisYear: :b370
121
- :SubjectSchemeVersion: :b068
122
- :ReturnsCode: :j269
123
- :ExtentValue: :b219
124
- :Conference: :conference
125
- :MarketPublishingDetail: :marketpublishingdetail
126
- :WebsiteDescription: :b294
127
- :Tax: :tax
128
- :PriceConditionQuantityType: :x464
129
- :ImprintName: :b079
130
- :ContentDetail: :contentdetail
131
- :PublishingRole: :b291
132
- :CopyrightYear: :b087
133
- :AudienceCode: :b073
134
- :OrderTime: :j144
135
- :ExpectedDate: :j302
136
- :PrizeJury: :g343
137
- :ReissueDate: :j365
138
- :ProductFormFeatureValue: :b335
139
- :NameIdentifier: :nameidentifier
140
- :BiblePurpose: :b354
141
- :TextItemIDType: :b285
142
- :ResourceForm: :x441
143
- :CollectionType: :x329
144
- :LocationIDType: :j377
145
- :TitleType: :b202
146
- :SupplierName: :j137
147
- :SalesOutletIDType: :b393
148
- :DefaultCurrencyCode: :m186
149
- :PriceAmount: :j151
150
- :IDTypeName: :b233
151
- :ConferenceSponsorIDType: :b391
152
- :PublisherIdentifier: :publisheridentifier
153
- :ContributorRole: :b035
154
- :AgentName: :j401
155
- :NumberOfIllustrations: :b125
156
- :PriceTypeDescription: :j262
157
- :RecordSourceIDType: :x311
158
- :ProductContentType: :b385
159
- :MeasureType: :x315
160
- :CurrencyCode: :j152
161
- :AudienceRangeValue: :b076
162
- :PositionOnList: :x433
163
- :SourceName: :x330
164
- :ReligiousTextFeatureDescription: :b360
165
- :ProfessionalPosition: :b045
166
- :CitationNote: :x434
167
- :LanguageRole: :b253
168
- :NoEdition: :n386
169
- :EditionNumber: :b057
170
- :TitleDetail: :titledetail
171
- :Subtitle: :b029
172
- :ReturnsCodeType: :j268
173
- :ExtentValueRoman: :x421
174
- :ConferenceAcronym: :b341
175
- :MarketPublishingStatus: :j407
176
- :WebsiteLink: :b295
177
- :TaxAmount: :x474
178
- :Addressee: :addressee
179
- :PriceConditionType: :x463
180
- :InitialPrintRun: :k167
181
- :ContentItem: :contentitem
182
- :PublishingStatus: :b394
183
- :PrizeName: :g126
184
- :CorporateName: :b047
185
- :AudienceCodeType: :b204
186
- :PackQuantity: :j145
187
- :Extent: :extent
188
- :ReissueDescription: :j366
189
- :ProductIDType: :b221
190
- :NameIDType: :x415
191
- :BibleReferenceLocation: :b356
192
- :TextItemIdentifier: :textitemidentifier
193
- :ResourceLink: :x435
194
- :ComparisonProductPrice: :comparisonproductprice
195
- :LocationName: :j349
196
- :TitleWithoutPrefix: :b031
197
- :SupplierOwnCoding: :supplierowncoding
198
- :SalesOutletName: :b382
199
- :DefaultLanguageOfText: :m184
200
- :PriceCode: :x468
201
- :IDValue: :b244
202
- :ConferenceSponsorIdentifier: :conferencesponsoridentifier
203
- :StockQuantityCode: :j297
204
- :PublisherIDType: :x447
205
- :PrimaryContentType: :x416
206
- :ContributorStatement: :b049
207
- :AgentRole: :j402
208
- :NumberOfItemsOfThisForm: :x322
209
- :EndDate: :b325
210
- :RecordSourceName: :a197
211
- :ProductForm: :b012
212
- :PositionOnProduct: :x313
213
- :MeasureUnitCode: :c095
214
- :CurrencyZone: :x475
215
- :Barcode: :barcode
216
- :SourceTitle: :x428
217
- :ReligiousTextFeatureType: :b358
218
- :PromotionCampaign: :k165
219
- :NotificationType: :a002
220
- :EditionStatement: :b058
221
- :CitedContent: :citedcontent
222
- :LastPageNumber: :b287
223
- :TitleElement: :titleelement
224
- :SuffixToKey: :b248
225
- :ReturnsCodeTypeName: :x460
226
- :MarketPublishingStatusNote: :x406
227
- :FaxNumber: :j271
228
- :ConferenceDate: :b054
229
- :WebsiteRole: :b367
230
- :TaxRateCode: :x471
231
- :PriceDate: :pricedate
232
- :KeyNames: :b040
233
- :Contributor: :contributor
234
- :AddresseeIdentifier: :addresseeidentifier
235
- :PublishingStatusNote: :b395
236
- :PrizeYear: :g127
237
- :PageRun: :pagerun
238
- :CorporateNameInverted: :x443
239
- :AudienceCodeTypeName: :b205
240
- :RelatedMaterial: :relatedmaterial
241
- :ProductIdentifier: :productidentifier
242
- :NamesAfterKey: :b041
243
- :DiscountAmount: :x469
244
- :BibleTextFeature: :b357
245
- :TextItemType: :b290
246
- :ResourceMode: :x437
247
- :MainSubject: :x425
248
- :Complexity: :complexity
249
- :ToLanguage: :x413
250
- :SupplierRole: :j292
251
- :SalesRestriction: :salesrestriction
252
- :PriceCoded: :pricecoded
253
- :Illustrated: :x422
254
- :ConferenceTheme: :b342
255
- :DefaultPriceType: :x310
256
- :Text: :d104
257
- :StockQuantityCodeType: :j293
258
- :PublisherName: :b081
259
- :NumberOfPages: :b061
260
- :EpubUsageConstraint: :epubusageconstraint
261
- :PrimaryPart: :x457
262
- :CopiesSold: :k168
263
- :AlternativeName: :alternativename
264
- :RecordSourceType: :a194
265
- :ProductFormDescription: :b014
266
- :MessageNote: :m183
267
- :BarcodeType: :x312
268
- :PrefixToKey: :b247
269
- :SourceType: :x431
270
- :ReligiousTextIdentifier: :b376
271
- :PromotionContact: :k166
272
- :LatestReprintNumber: :x446
273
- :EditionType: :x419
274
- :CitedContentType: :x430
275
- :TitleElementLevel: :x409
276
- :Supplier: :supplier
277
- :ReturnsConditions: :returnsconditions
278
- :FeatureNote: :x440
279
- :ConferenceName: :b052
280
- :Measure: :measure
281
- :WorkIdentifier: :workidentifier
282
- :TaxRatePercent: :x472
283
- :PriceDateRole: :x476
284
- :Language: :language
285
- :ContributorDate: :contributordate
286
- :AddresseeIDType: :m380
287
- :Header: :header
288
- :Quantity: :x320
289
- :ProductAvailability: :j396
290
- :CountriesIncluded: :x449
291
- :AudienceCodeValue: :b206
292
- :PartNumber: :x410
293
- :SenderIDType: :m379
294
- :RelatedProduct: :relatedproduct
295
- :ProductPackaging: :b225
296
- :NamesBeforeKey: :b039
297
- :DiscountCode: :j364
298
- :BibleTextOrganization: :b355
299
- :TextSourceCorporate: :b374
300
- :SubjectCode: :b069
301
- :ResourceVersion: :resourceversion
302
- :ComplexityCode: :b078
303
- :MapScale: :b063
304
- :TradeCategory: :b384
305
- :SupplyDate: :supplydate
306
- :SalesRestrictionNote: :x453
307
- :PriceCodeType: :x465
308
- :IllustrationsNote: :b062
309
- :ContactName: :x299
310
- :DeletionText: :a199
311
- :StockQuantityCodeTypeName: :j296
312
- :PublisherRepresentative: :publisherrepresentative
313
- :AncillaryContent: :ancillarycontent
314
- :ONIXMessage: :ONIXmessage
315
- :EpubUsageLimit: :epubusagelimit
316
- :PrintedOnProduct: :x301
317
- :CopyrightOwner: :copyrightowner
318
- :RegionCode: :b398
319
- :ProductFormDetail: :b333
320
- :Date: :b306
321
- :MessageNumber: :m180
322
- :BatchBonus: :batchbonus
323
- :Price: :price
324
- :StartDate: :b324
325
- :ReprintDetail: :k309
326
- :Publisher: :publisher
327
- :LettersAfterNames: :b042
328
- :EditionVersionNumber: :b217
329
- :CityOfPublication: :b209
330
- :TitlePrefix: :b030
331
- :SupplierCodeType: :x458
332
- :SalesRights: :salesrights
333
- :FeatureValue: :x439
334
- :ConferenceNumber: :b053
335
- :Number: :b257
336
- :WorkIDType: :b201
337
- :TaxableAmount: :x473
338
- :PricePer: :j239
339
- :ContributorDateRole: :x417
340
- :AddresseeName: :x300
341
- :QuantityUnit: :x466
342
- :ProductClassification: :productclassification
343
- :CountriesExcluded: :x451
344
- :AudienceDescription: :b207
345
- :Percent: :b337
346
- :SenderIdentifier: :senderidentifier
347
- :RelatedWork: :relatedwork
348
- :ProductPart: :productpart
349
- :NameType: :x414
350
- :DiscountCodeType: :j363
351
- :BibleVersion: :b353
352
- :TextType: :x426
353
- :SubjectHeadingText: :b070
354
- :ResourceVersionFeature: :resourceversionfeature
355
- :ComplexitySchemeIdentifier: :b077
356
- :Market: :market
357
- :UnnamedPersons: :b249
358
- :SupplyDateRole: :x461
359
- :SalesRestrictionType: :b381
360
- :DescriptiveDetail: :descriptivedetail
361
- :PriceCodeTypeName: :x477
362
- :Collection: :collection
363
- :Imprint: :imprint
364
- :ContentAudience: :x427
365
- :StockQuantityCoded: :stockquantitycoded
366
- :PublishingDate: :publishingdate
367
- :Prize: :prize
368
- :CopyrightOwnerIDType: :b392
369
- :AncillaryContentType: :x423
370
- :OnHand: :j350
371
- :EpubUsageStatus: :x319
372
- :RegionsIncluded: :x450
373
- :ProductFormFeature: :productformfeature
374
- :MessageRepeat: :m181
375
- :BatchQuantity: :j264
376
- :TextAuthor: :d107
377
- :Stock: :stock
378
- :ResourceContentType: :x436
379
- :CollateralDetail: :collateraldetail
380
- :LevelSequenceNumber: :b284
381
- :TitlesAfterNames: :b043
382
- :SupplierCodeValue: :x459
383
- :SalesRightsType: :b089
384
- :FirstPageNumber: :b286
385
- :ConferencePlace: :b055
386
-
387
- # TAGI NIESTANDARDOWE
388
- :CoverType: :cover_type