Class: RelatonBib::Address

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

Overview

Address class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(street:, city:, state: nil, country:, postcode: nil) ⇒ Address

Returns a new instance of Address.

Parameters:

  • street (Array<String>)
  • city (String)
  • state (String) (defaults to: nil)
  • country (String)
  • postcode (String) (defaults to: nil)


28
29
30
31
32
33
34
# File 'lib/relaton_bib/contributor.rb', line 28

def initialize(street:, city:, state: nil, country:, postcode: nil)
  @street   = street
  @city     = city
  @state    = state
  @country  = country
  @postcode = postcode
end

Instance Attribute Details

#cityString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/relaton_bib/contributor.rb', line 12

def city
  @city
end

#countryString (readonly)

Returns:

  • (String)


18
19
20
# File 'lib/relaton_bib/contributor.rb', line 18

def country
  @country
end

#postcodeString, NilClass (readonly)

Returns:

  • (String, NilClass)


21
22
23
# File 'lib/relaton_bib/contributor.rb', line 21

def postcode
  @postcode
end

#stateString, NilClass (readonly)

Returns:

  • (String, NilClass)


15
16
17
# File 'lib/relaton_bib/contributor.rb', line 15

def state
  @state
end

#streetArray<String> (readonly)

Returns:

  • (Array<String>)


9
10
11
# File 'lib/relaton_bib/contributor.rb', line 9

def street
  @street
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


48
49
50
51
52
53
54
55
56
# File 'lib/relaton_bib/contributor.rb', line 48

def to_hash
  hash = {}
  hash["street"] = street if street&.any?
  hash["city"] = city
  hash["state"] = state if state
  hash["country"] = country
  hash["postcode"] = postcode if postcode
  hash
end

#to_xml(doc) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Document)


37
38
39
40
41
42
43
44
45
# File 'lib/relaton_bib/contributor.rb', line 37

def to_xml(doc)
  doc.address do
    street.each { |str| doc.street str }
    doc.city city
    doc.state state if state
    doc.country country
    doc.postcode postcode if postcode
  end
end