Class: RelatonBib::BibItemLocality

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/bib_item_locality.rb

Overview

Bibliographic item locality.

Direct Known Subclasses

Locality, SourceLocality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, reference_from, reference_to = nil) ⇒ BibItemLocality

Returns a new instance of BibItemLocality.

Parameters:

  • type (String)
  • referenceFrom (String)
  • referenceTo (String, NilClass)


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|whole|table|
    annex|figure|note|list|example|volume|issue|time|
    locality:[a-zA-Z0-9_]+}x
  unless type =~ type_ptrn
    warn "[relaton-bib] WARNING: invalid locality type: #{type}"
  end

  @type           = type
  @reference_from = reference_from
  @reference_to   = reference_to
end

Instance Attribute Details

#reference_fromString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/relaton_bib/bib_item_locality.rb', line 8

def reference_from
  @reference_from
end

#reference_toString, NilClass (readonly)

Returns:

  • (String, NilClass)


11
12
13
# File 'lib/relaton_bib/bib_item_locality.rb', line 11

def reference_to
  @reference_to
end

#typeString (readonly)

Returns:

  • (String)


5
6
7
# File 'lib/relaton_bib/bib_item_locality.rb', line 5

def type
  @type
end

Instance Method Details

#to_hashHash

Returns:

  • (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

Parameters:

  • builder (Nokogiri::XML::Builder)


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