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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ TitleElement

Returns a new instance of TitleElement.



8
9
10
11
12
13
14
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 8

def initialize(data)
  @to_xml = data.to_s
  @level = data.at_css('TitleElementLevel')&.text
  @part_number = data.at_css('PartNumber')&.text
  @title = data.at_css('TitleText')&.text
  @subtitle = data.at_css('Subtitle')&.text
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 6

def level
  @level
end

#part_numberObject

Returns the value of attribute part_number.



6
7
8
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 6

def part_number
  @part_number
end

#subtitleObject

Returns the value of attribute subtitle.



6
7
8
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 6

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



6
7
8
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 6

def title
  @title
end

#to_xmlObject

Returns the value of attribute to_xml.



6
7
8
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 6

def to_xml
  @to_xml
end

Instance Method Details

#full_titleObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elibri_onix/onix_3_0/title_element.rb', line 16

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 && self.subtitle.size > 0
    else
      _full_title << ". " + self.subtitle if self.subtitle && self.subtitle.size > 0
    end
    if self.part_number && self.part_number.size > 0
      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