Module: Elibri::ONIX::Generator

Extended by:
ActiveSupport::Concern
Defined in:
lib/elibri_onix_generator.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SHORT_TAGS =
YAML::load_file(File.dirname(__FILE__) + "/xml_tags.yml")
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"]

Instance Method Summary collapse

Instance Method Details

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



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
147
148
149
150
151
152
# File 'lib/elibri_onix_generator.rb', line 122

def initialize(products, options = {})
  options.reverse_merge!({
    :tags_type => :full,
    :export_headers => true,
    :elibri_onix_dialect => '3.0.1',
    :comments => false,
    :xml_variant => Elibri::XmlVariant::FULL_VARIANT
  })

  @xml_variant = options[:xml_variant]
  raise ":xml_variant unspecified" if @xml_variant.blank? or !@xml_variant.kind_of?(::Elibri::XmlVariant)

  @products = Array.wrap(products)
  @tags_type = ActiveSupport::StringInquirer.new(options[:tags_type].to_s)
  @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, :short_tags => tags_type.short?, :elibri_onix_dialect => @elibri_onix_dialect, :pure_onix => @pure_onix) do
      render_products!
    end
  else
    render_products!
  end
end

#to_sObject



155
156
157
# File 'lib/elibri_onix_generator.rb', line 155

def to_s
  @out.join
end