Class: IsoBibItem::BibliographicDate
- Inherits:
-
Object
- Object
- IsoBibItem::BibliographicDate
- Defined in:
- lib/iso_bib_item/bibliographic_date.rb
Overview
Bibliographic date.
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.
23 24 25 26 27 28 29 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 23 def initialize(type:, on: nil, from: nil, to: nil) raise ArgumentError, 'expected :on or :form argument' unless on || from @type = type @on = parse_date on @from = parse_date from @to = parse_date to end |
Instance Attribute Details
#from ⇒ Time (readonly)
12 13 14 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 12 def from @from end |
#on ⇒ Time (readonly)
18 19 20 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 18 def on @on end |
#to ⇒ Time (readonly)
15 16 17 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 15 def to @to end |
#type ⇒ String (readonly)
9 10 11 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 9 def type @type end |
Instance Method Details
#to_xml(builder, **opts) ⇒ Nokogiri::XML::Builder
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 35 def to_xml(builder, **opts) builder.date(type: type) do if on builder.on(opts[:no_year] ? '--' : on.year) else builder.from(opts[:no_year] ? '--' : from.year) builder.to to.year if to end end end |