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

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

Constant Summary collapse

ATTRIBUTES =
[
  :type, :type_name, :full_title, :product_level_title, :product_level, :collection_level_title,
  :collection_level
]
RELATIONS =
[
  :elements, :inspect_include_fields
]

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) ⇒ TitleDetail

Returns a new instance of TitleDetail.



27
28
29
30
31
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 27

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

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



25
26
27
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 25

def elements
  @elements
end

#to_xmlObject

Returns the value of attribute to_xml.



25
26
27
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 25

def to_xml
  @to_xml
end

#typeObject

Returns the value of attribute type.



25
26
27
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 25

def type
  @type
end

Instance Method Details

#collection_levelObject



63
64
65
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 63

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

#collection_level_titleObject



59
60
61
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 59

def collection_level_title
  collection_level.try(:full_title)
end

#full_titleObject



41
42
43
44
45
46
47
48
49
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 41

def full_title
  String.new.tap do |_full_title|
    _full_title << collection_level_title if collection_level_title.present?
    if product_level_title.present?
      _full_title << ". " if _full_title.present?
      _full_title << product_level_title 
    end
  end
end

#inspect_include_fieldsObject



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

def inspect_include_fields
  [:type_name]
end

#product_levelObject



55
56
57
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 55

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

#product_level_titleObject



51
52
53
# File 'lib/elibri_onix/onix_3_0/title_detail.rb', line 51

def product_level_title
  product_level.try(:full_title)
end

#type_nameObject



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

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