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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ PublishingDate

Returns a new instance of PublishingDate.



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

def initialize(data)
  @to_xml = data.to_s
  @role = data.at_css('PublishingDateRole')&.text
  @format = data.at_css('DateFormat')&.text || data.at_css('Date')['dateformat'] || '00'
  @date = data.at_css('Date')&.text
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#to_xmlObject

Returns the value of attribute to_xml.



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

def to_xml
  @to_xml
end

Instance Method Details

#parsedObject



15
16
17
18
19
20
21
# File 'lib/elibri_onix/onix_3_0/publishing_date.rb', line 15

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