Class: Elibri::ONIX::Release_3_0::TitleElement

Inherits:
Object
  • Object
show all
Includes:
HashId
Defined in:
lib/elibri_onix/onix_3_0/title_element.rb

Constant Summary collapse

ATTRIBUTES =
[
  :level, :part_number, :title, :subtitle, :full_title
]
RELATIONS =
[]

Constants included from HashId

HashId::SKIPPED_2, HashId::SKIPPED_ATTRIBS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashId

#calculate_hash, #eid

Constructor Details

#initialize(data) ⇒ TitleElement

Returns a new instance of TitleElement.



31
32
33
34
35
36
37
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 31

def initialize(data)
  @to_xml = data.to_s
  @level = data.at_xpath('xmlns:TitleElementLevel').try(:text)
  @part_number = data.at_xpath('xmlns:PartNumber').try(:text)
  @title = data.at_xpath('xmlns:TitleText').try(:text)
  @subtitle = data.at_xpath('xmlns:Subtitle').try(:text)
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 29

def level
  @level
end

#part_numberObject

Returns the value of attribute part_number.



29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 29

def part_number
  @part_number
end

#subtitleObject

Returns the value of attribute subtitle.



29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 29

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 29

def title
  @title
end

#to_xmlObject

Returns the value of attribute to_xml.



29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 29

def to_xml
  @to_xml
end

Instance Method Details

#full_titleObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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