class Elibri::ONIX::Release_3_0::TitleElement

Constants

ATTRIBUTES
RELATIONS

Attributes

level[RW]
part_number[RW]
subtitle[RW]
title[RW]
to_xml[RW]

Public Class Methods

new(data) click to toggle source
# File lib/elibri_onix/onix_3_0/title_element.rb, line 31
def initialize(data)
  @to_xml = data.to_s
  @level = data.at_css('TitleElementLevel').try(:text)
  @part_number = data.at_css('PartNumber').try(:text)
  @title = data.at_css('TitleText').try(:text)
  @subtitle = data.at_css('Subtitle').try(:text)
end

Public Instance Methods

full_title() click to toggle source
# File lib/elibri_onix/onix_3_0/title_element.rb, line 39
def full_title
  String.new(self.title.to_s.strip).tap do |_full_title|
    if _full_title =~ /[\.!\?]$/ #czy kończy się ?!.
      _full_title << " " + self.subtitle if self.subtitle.present?
    else
      _full_title << ". " + self.subtitle if self.subtitle.present?
    end
    if self.part_number.present?
      if self.part_number.to_i.to_s == self.part_number
        _full_title << " (##{self.part_number})" 
      else
        _full_title << " (#{self.part_number})"
      end 
    end
  end
end