Class: RelatonBib::Address
Overview
Address class.
Instance Attribute Summary collapse
- #city ⇒ String readonly
- #country ⇒ String readonly
- #postcode ⇒ String, NilClass readonly
- #state ⇒ String, NilClass readonly
- #street ⇒ Array<String> readonly
Instance Method Summary collapse
-
#initialize(street:, city:, state: nil, country:, postcode: nil) ⇒ Address
constructor
A new instance of Address.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(doc) ⇒ Object
Constructor Details
#initialize(street:, city:, state: nil, country:, postcode: nil) ⇒ Address
Returns a new instance of Address.
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
#city ⇒ String (readonly)
12 13 14 |
# File 'lib/relaton_bib/contributor.rb', line 12 def city @city end |
#country ⇒ String (readonly)
18 19 20 |
# File 'lib/relaton_bib/contributor.rb', line 18 def country @country end |
#postcode ⇒ String, NilClass (readonly)
21 22 23 |
# File 'lib/relaton_bib/contributor.rb', line 21 def postcode @postcode end |
#state ⇒ String, NilClass (readonly)
15 16 17 |
# File 'lib/relaton_bib/contributor.rb', line 15 def state @state end |
#street ⇒ Array<String> (readonly)
9 10 11 |
# File 'lib/relaton_bib/contributor.rb', line 9 def street @street end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/relaton_bib/contributor.rb', line 61 def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize pref = prefix.empty? ? "address" : prefix + ".address" out = count > 1 ? "#{pref}::\n" : "" street.each { |st| out += "#{pref}.street:: #{st}\n" } out += "#{pref}.city:: #{city}\n" out += "#{pref}.state:: #{state}\n" if state out += "#{pref}.country:: #{country}\n" out += "#{pref}.postcode:: #{postcode}\n" if postcode out end |
#to_hash ⇒ 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
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 |