Class: RelatonBib::BibliographicDate
- Defined in:
- lib/relaton_bib/bibliographic_date.rb
Overview
Bibliographic date.
Constant Summary collapse
- TYPES =
%w[published accessed created implemented obsoleted confirmed updated issued transmitted copied unchanged circulated adapted].freeze
Instance Attribute Summary collapse
- #from ⇒ Date readonly
- #on ⇒ Date readonly
- #to ⇒ Date readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(type:, on: nil, from: nil, to: nil) ⇒ BibliographicDate
constructor
A new instance of BibliographicDate.
- #to_hash ⇒ Hash
- #to_xml(builder, **opts) ⇒ Nokogiri::XML::Builder
Constructor Details
#initialize(type:, on: nil, from: nil, to: nil) ⇒ BibliographicDate
Returns a new instance of BibliographicDate.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 27 def initialize(type:, on: nil, from: nil, to: nil) raise ArgumentError, "expected :on or :from argument" unless on || from # raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type @type = type @on = RelatonBib.parse_date on @from = RelatonBib.parse_date from @to = RelatonBib.parse_date to end |
Instance Attribute Details
#from ⇒ Date (readonly)
15 16 17 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 15 def from @from end |
#on ⇒ Date (readonly)
21 22 23 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 21 def on @on end |
#to ⇒ Date (readonly)
18 19 20 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 18 def to @to end |
#type ⇒ String (readonly)
12 13 14 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 12 def type @type end |
Instance Method Details
#to_hash ⇒ Hash
55 56 57 58 59 60 61 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 55 def to_hash hash = { "type" => type } hash["value"] = on.to_s if on hash["from"] = from.to_s if from hash["to"] = to.to_s if to hash end |
#to_xml(builder, **opts) ⇒ Nokogiri::XML::Builder
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 42 def to_xml(builder, **opts) builder.date(type: type) do if on builder.on(opts[:no_year] ? "--" : date_format(on, opts[:date_format])) elsif from builder.from(opts[:no_year] ? "--" : date_format(from, opts[:date_format])) builder.to date_format(to, opts[:date_format]) if to end end end |