Class: Elibri::ONIX::Release_3_0::PublishingDate

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

Constant Summary collapse

ATTRIBUTES =
[
  :role, :format, :date, :parsed
]
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) ⇒ PublishingDate

Returns a new instance of PublishingDate.



25
26
27
28
29
30
# File 'lib/elibri_onix/onix_3_0/publishing_date.rb', line 25

def initialize(data)
  @to_xml = data.to_s
  @role = data.at_xpath('xmlns:PublishingDateRole').try(:text)
  @format = data.at_xpath('xmlns:DateFormat').try(:text)
  @date = data.at_xpath('xmlns:Date').try(:text)
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#to_xmlObject

Returns the value of attribute to_xml.



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

def to_xml
  @to_xml
end

Instance Method Details

#parsedObject



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

def parsed
  case @format
    when '00' then [date[0...4].to_i, date[4...6].to_i, date[6...8].to_i]
    when '01' then [date[0...4].to_i, date[4...6].to_i]
    when '05' then [date[0...4].to_i]
  end
end