Module: Elibri::ONIX::Generator

Included in:
Model::Product::OnixGenerator
Defined in:
lib/elibri_onix_generator.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

DOC_ORDER =
["record_identifiers", "publishing_status", "product_form", "contributors", "titles", "series_memberships", "measurement",
"sale_restrictions", "territorial_rights", "audience_range", "publisher_info", "extent", "edition", "languages", "epub_details",
"texts", "supporting_resources", "subjects", "pform_features", "elibri_extensions"]
DEFAULT_DIALECT =
'3.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
# File 'lib/elibri_onix_generator.rb', line 15

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#initialize(products, options = {}) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/elibri_onix_generator.rb', line 107

def initialize(products, options = {})
  options[:export_headers] =  true unless options.has_key?(:export_headers)
  options[:elibri_onix_dialect] = DEFAULT_DIALECT unless options.has_key?(:elibri_onix_dialect)
  options[:comments] = false unless options.has_key?(:comments)
  options[:xml_variant] = OpenStruct.new(blank?: false,
                                         includes_basic_meta?: true,
                                         includes_other_texts?: true,
                                         includes_media_files?: true,
                                         includes_stocks?: true) unless options.has_key?(:xml_variant)

  @xml_variant = options[:xml_variant]
  raise ":xml_variant unspecified" if @xml_variant.blank?

  if products.respond_to?(:to_ary)
    @products = products.to_ary
  else
    @products = [products]
  end
  @comments = options[:comments]
  @comment_kinds = options[:comment_kinds]
  @out = []
  @builder = Builder::XmlMarkup.new(:indent => 2, :target => @out)
  @elibri_onix_dialect = options[:elibri_onix_dialect]
  # Gdy true, ignorujemy rozszerzenia eLibri
  @pure_onix = options[:pure_onix] || options[:elibri_onix_dialect]  == '3.0.2'
  @skip_sourcename_and_timestamp = !!options[:skip_sourcename_and_timestamp]
  @sender_name = options[:sender_name]
  @lan = options[:lan] || "pol"

  # W testach często nie chcę żadnych nagłówków - interesuje mnie tylko tag <Product>
  if options[:export_headers]
    self.class.render_header(@builder, elibri_onix_dialect: @elibri_onix_dialect, pure_onix: @pure_onix || !@xml_variant.includes_basic_meta?, sender_name: @sender_name) do
      render_products!
    end
  else
    render_products!
  end
end

#to_sObject



147
148
149
# File 'lib/elibri_onix_generator.rb', line 147

def to_s
  @out.join
end