lib/iso_bib_item/contributor.rb in iso-bib-item-0.1.6 vs lib/iso_bib_item/contributor.rb in iso-bib-item-0.1.7

- old
+ new

@@ -1,16 +1,72 @@ # frozen_string_literal: true require 'uri' module IsoBibItem - # Contact method. - class ContactMethod - # @return [String] @todo TBD - attr_reader :contact + # Address class. + class Address + # @return [Array<String>] + attr_reader :street + + # @return [String] + attr_reader :city + + # @return [String, NilClass] + attr_reader :state + + # @return [String] + attr_reader :country + + # @return [String, NilClass] + attr_reader :postcode + + # @param street [Array<String>] + # @param city [String] + # @param state [String] + # @param country [String] + # @param postcode [String] + def initialize(street:, city:, state: nil, country:, postcode: nil) + @street = street + @city = city + @state = state + @country = country + @postcode = postcode + end + + # @param builder [Nokogiri::XML::Document] + 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 end + # Contact class. + class Contact + # @return [String] allowed "phone", "email" or "uri" + attr_reader :type + + # @return [String] + attr_reader :value + + # @param phone [String] + def initialize(type:, value:) + @type = type + @value = value + end + + # @param builder [Nokogiri::XML::Document] + def to_xml(doc) + doc.send type, value + end + end + # Affilation. class Affilation # @return [IsoBibItem::LocalizedString] attr_reader :name @@ -23,23 +79,32 @@ # @param organization [IsoBibItem::Organization] def initialize(organization) @organization = organization @description = [] end + + def to_xml(builder) + builder.affilation do + builder.name { name.to_xml builder } if name + description.each { |d| builder.description { d.to_xml builder } } + organization.to_xml builder + end + end end # Contributor. class Contributor # @return [URI] attr_reader :uri - # @return [Array<IsoBibItem::ContactMethod>] + # @return [Array<IsoBibItem::Address, IsoBibItem::Phone>] attr_reader :contacts # @param url [String] - def initialize(url = nil) + # @param contacts [Array<IsoBibItem::Address, IsoBibItem::Phone>] + def initialize(url: nil, contacts: []) @uri = URI url if url - @contacts = [] + @contacts = contacts end # @return [String] def url @uri.to_s