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
- #==(other) ⇒ Object
-
#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
#==(other) ⇒ Object
33 34 35 36 37 |
# File 'lib/relaton_bib/contributor.rb', line 33 def ==(other) street == other.street && city == other.city && state == other.state && country == other.country && postcode == other.postcode && formatted_address == other.formatted_address end |
#to_asciibib(prefix = "", count = 1) ⇒ String
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/relaton_bib/contributor.rb', line 72 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
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/relaton_bib/contributor.rb', line 55 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
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/relaton_bib/contributor.rb', line 40 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 |