Class: Elibri::ONIX::Release_3_0::SupportingResource

Inherits:
Object
  • Object
show all
Includes:
ExternalId, ExternalTimestamp, Inspector
Defined in:
lib/elibri_onix/onix_3_0/supporting_resource.rb

Constant Summary collapse

ATTRIBUTES =

from ONIX documentation: An optional and repeatable group of data elements which together describe a supporting resource.

[
  :content_type, :mode, :form, :link, :content_type_name, :mode_name, :form_name
]
RELATIONS =
[
  :inspect_include_fields
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspector

#attribute_for_inspect, #inspect

Methods included from ExternalTimestamp

#datestamp, included, #set_datestamp

Methods included from ExternalId

#eid, included, #set_eid

Constructor Details

#initialize(data) ⇒ SupportingResource

Returns a new instance of SupportingResource.



25
26
27
28
29
30
31
32
33
34
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 25

def initialize(data)
  @data = data
  @to_xml = data.to_s
  @content_type = data.at_css('ResourceContentType').try(:text)
  @mode = data.at_css('ResourceMode').try(:text)
  @form = data.at_css('ResourceVersion').at_css('ResourceForm').try(:text)
  @link = data.at_css('ResourceVersion').at_css('ResourceLink').try(:text)
  set_eid(data)
  set_datestamp(data)
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def content_type
  @content_type
end

#dataObject

Returns the value of attribute data.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def data
  @data
end

#formObject

Returns the value of attribute form.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def form
  @form
end

Returns the value of attribute link.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def link
  @link
end

#modeObject

Returns the value of attribute mode.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def mode
  @mode
end

#to_xmlObject

Returns the value of attribute to_xml.



23
24
25
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 23

def to_xml
  @to_xml
end

Instance Method Details

#content_type_nameObject



36
37
38
39
40
41
42
43
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 36

def content_type_name
  content_type = Elibri::ONIX::Dict::Release_3_0::ResourceContentType.find_by_onix_code(@content_type)
  if content_type
    content_type.const_name.downcase
  else
    raise ArgumentError, "Cannot find ResourceContentType for #{@content_type}"
  end
end

#form_nameObject



53
54
55
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 53

def form_name
  Elibri::ONIX::Dict::Release_3_0::ResourceForm.find_by_onix_code(@form).const_name.downcase
end

#inspect_include_fieldsObject



57
58
59
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 57

def inspect_include_fields
  [:content_type_name, :mode_name, :form_name]
end

#mode_nameObject

def audience_name

Elibri::ONIX::Dict::Release_3_0::ContentAudience.find_by_onix_code(audience).const_name.downcase

end



49
50
51
# File 'lib/elibri_onix/onix_3_0/supporting_resource.rb', line 49

def mode_name
  Elibri::ONIX::Dict::Release_3_0::ResourceMode.find_by_onix_code(@mode).const_name.downcase
end