Class: RelatonBib::Address
Overview
Address class.
Instance Attribute Summary collapse
- #city ⇒ String? readonly
- #country ⇒ String? readonly
- #formatted_address ⇒ String? readonly
- #postcode ⇒ String? readonly
- #state ⇒ String? readonly
- #street ⇒ Array<String> readonly
Instance Method Summary collapse
-
#initialize(**args) ⇒ Address
constructor
A new instance of Address.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(doc) ⇒ Object
Constructor Details
#initialize(**args) ⇒ Address
Returns a new instance of Address.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/relaton_bib/contributor.rb', line 20 def initialize(**args) # rubocop:disable Metrics/CyclomaticComplexity unless args[:formatted_address] || (args[:city] && args[:country]) raise ArgumentError, "Either formatted address or city and country must be provided" end @street = args[:street] || [] @city = args[:city] @state = args[:state] @country = args[:country] @postcode = args[:postcode] @formatted_address = args[:formatted_address] unless args[:city] && args[:country] 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)
12 13 14 |
# File 'lib/relaton_bib/contributor.rb', line 12 def country @country end |
#formatted_address ⇒ String? (readonly)
12 13 14 |
# File 'lib/relaton_bib/contributor.rb', line 12 def formatted_address @formatted_address end |
#postcode ⇒ String? (readonly)
12 13 14 |
# File 'lib/relaton_bib/contributor.rb', line 12 def postcode @postcode end |
#state ⇒ String? (readonly)
12 13 14 |
# File 'lib/relaton_bib/contributor.rb', line 12 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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/relaton_bib/contributor.rb', line 66 def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity pref = prefix.empty? ? "address" : "#{prefix}.address" if formatted_address "#{pref}.formatted_address:: #{formatted_address}\n" else 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 end |
#to_hash ⇒ Hash
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/relaton_bib/contributor.rb', line 49 def to_hash # rubocop:disable Metrics/AbcSize, Metrics/MethodLength hash = { "address" => {} } if formatted_address hash["address"]["formatted_address"] = formatted_address else hash["address"]["street"] = street if street.any? hash["address"]["city"] = city hash["address"]["state"] = state if state hash["address"]["country"] = country hash["address"]["postcode"] = postcode if postcode end hash end |
#to_xml(doc) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/relaton_bib/contributor.rb', line 34 def to_xml(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength doc.address do if formatted_address doc.formattedAddress formatted_address else street.each { |str| doc.street str } doc.city city doc.state state if state doc.country country doc.postcode postcode if postcode end end end |