Class: RelatonBib::BibliographicDate
- Inherits:
-
Object
- Object
- 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].freeze
Instance Attribute Summary collapse
- #from ⇒ Time readonly
- #on ⇒ Time readonly
- #to ⇒ Time readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(type:, on: nil, from: nil, to: nil) ⇒ BibliographicDate
constructor
A new instance of BibliographicDate.
- #to_xml(builder, **opts) ⇒ Nokogiri::XML::Builder
Constructor Details
#initialize(type:, on: nil, from: nil, to: nil) ⇒ BibliographicDate
Returns a new instance of BibliographicDate.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 26 def initialize(type:, on: nil, from: nil, to: nil) raise ArgumentError, "expected :on or :form argument" unless on || from raise ArgumentError, %{Type "#{type}" is ivalid.} unless TYPES.include?(type) @type = type @on = parse_date on @from = parse_date from @to = parse_date to end |
Instance Attribute Details
#from ⇒ Time (readonly)
15 16 17 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 15 def from @from end |
#on ⇒ Time (readonly)
21 22 23 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 21 def on @on end |
#to ⇒ Time (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_xml(builder, **opts) ⇒ Nokogiri::XML::Builder
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/relaton_bib/bibliographic_date.rb', line 42 def to_xml(builder, **opts) builder.date(type: type) do if on date = opts[:full_date] ? on.strftime("%Y-%m") : on.year builder.on(opts[:no_year] ? "--" : date) elsif from if opts[:full_date] date_form = from.strftime("%Y-%m") date_to = to.strftime("%Y-%m") if to else date_form = from.year date_to = to.year if to end builder.from(opts[:no_year] ? "--" : date_form) builder.to date_to if to end end end |