Class: RelatonBib::BibItemLocality
- Defined in:
- lib/relaton_bib/bib_item_locality.rb
Overview
Bibliographic item locality.
Direct Known Subclasses
Instance Attribute Summary collapse
- #reference_from ⇒ String readonly
- #reference_to ⇒ String? readonly
- #type ⇒ String readonly
Instance Method Summary collapse
-
#initialize(type, reference_from, reference_to = nil) ⇒ BibItemLocality
constructor
A new instance of BibItemLocality.
- #to_asciibib(prefix = "", count = 1) ⇒ String
-
#to_bibtex(item) ⇒ Object
Render locality as BibTeX.
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(type, reference_from, reference_to = nil) ⇒ BibItemLocality
Returns a new instance of BibItemLocality.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 16 def initialize(type, reference_from, reference_to = nil) type_ptrn = %r{section|clause|part|paragraph|chapter|page|title|line| whole|table|annex|figure|note|list|example|volume|issue|time|anchor| locality:[a-zA-Z0-9_]+}x unless type&.match? type_ptrn Util.warn "Invalid locality type: `#{type}`" end @type = type @reference_from = reference_from @reference_to = reference_to end |
Instance Attribute Details
#reference_from ⇒ String (readonly)
8 9 10 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 8 def reference_from @reference_from end |
#reference_to ⇒ String? (readonly)
11 12 13 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 11 def reference_to @reference_to end |
#type ⇒ String (readonly)
5 6 7 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 5 def type @type end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
46 47 48 49 50 51 52 53 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 46 def to_asciibib(prefix = "", count = 1) pref = prefix.empty? ? prefix : "#{prefix}." out = count > 1 ? "#{prefix}::\n" : "" out += "#{pref}type:: #{type}\n" out += "#{pref}reference_from:: #{reference_from}\n" out += "#{pref}reference_to:: #{reference_to}\n" if reference_to out end |
#to_bibtex(item) ⇒ Object
Render locality as BibTeX.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 60 def to_bibtex(item) case type when "chapter" then item.chapter = reference_from when "page" value = reference_from value += "--#{reference_to}" if reference_to item.pages = value when "volume" then item.volume = reference_from when "issue" then item.number = reference_from end end |
#to_hash ⇒ Hash
37 38 39 40 41 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 37 def to_hash hash = { "type" => type, "reference_from" => reference_from } hash["reference_to"] = reference_to if reference_to hash end |
#to_xml(builder) ⇒ Object
30 31 32 33 34 |
# File 'lib/relaton_bib/bib_item_locality.rb', line 30 def to_xml(builder) builder.parent[:type] = type builder.referenceFrom reference_from # { reference_from.to_xml(builder) } builder.referenceTo reference_to if reference_to end |