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", "elibri_extensions"]
DEFAULT_DIALECT =
'3.0.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



18
19
20
# File 'lib/elibri_onix_generator.rb', line 18

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

Instance Method Details

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



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
145
146
# File 'lib/elibri_onix_generator.rb', line 112

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?: false) 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]

  # 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) do
      render_products!
    end
  else
    render_products!
  end
end

#to_sObject



149
150
151
# File 'lib/elibri_onix_generator.rb', line 149

def to_s
  @out.join
end