Class: Elibri::ONIX::Release_3_0::TitleDetail

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ TitleDetail



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

def initialize(data)
  @to_xml = data.to_s
  @type = data.at_css('TitleType')&.text
  @elements = data.css('TitleElement').map { |element_data| TitleElement.new(element_data) }
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



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

def elements
  @elements
end

#to_xmlObject

Returns the value of attribute to_xml.



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

def to_xml
  @to_xml
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#collection_levelObject



44
45
46
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 44

def collection_level
  @elements.find {|element| element.level == "02"}
end

#collection_level_titleObject



40
41
42
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 40

def collection_level_title
  collection_level&.full_title
end

#full_titleObject



22
23
24
25
26
27
28
29
30
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 22

def full_title
  String.new.tap do |_full_title|
    _full_title << collection_level_title if collection_level_title && collection_level_title.size > 0
    if product_level_title && product_level_title.size > 0
      _full_title << ". " if _full_title && _full_title.size > 0
      _full_title << product_level_title
    end
  end
end

#inspect_include_fieldsObject



18
19
20
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 18

def inspect_include_fields
  [:type_name]
end

#product_levelObject



36
37
38
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 36

def product_level
  @elements.find {|element| element.level == "01"}
end

#product_level_titleObject



32
33
34
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 32

def product_level_title
  product_level&.full_title
end

#type_nameObject



14
15
16
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 14

def type_name
   Elibri::ONIX::Dict::Release_3_0::TitleType.find_by_onix_code(self.type).const_name.downcase
end