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 45 46 47 48 49 50 51 52 |
# File 'lib/iso_bib_item/bibliographic_date.rb', line 35 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 |