Sha256: 7329092eed2bce937b45da119f4da49a300d84193084ca8ed69e9ad47e23a4cd

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

module GutenbergRdf
  class Rdf
    class Agent
      attr_reader :xml

      def initialize(xml)
        @xml = xml
      end

      def id
        xml.at_xpath('pgterms:agent').attribute('about').content.match(/\A\d\d\d\d\/agents\/(\d+)\z/)[1]
      end

      def fullname
        [firstname, lastname].join(' ')
      end

      def lastname
        @lastname ||= name_parts[:last]
      end

      def firstname
        @firstname ||= name_parts[:first]
      end

      def birthdate
        xml.at_xpath('pgterms:agent/pgterms:birthdate').text
      end

      def deathdate
        xml.at_xpath('pgterms:agent/pgterms:deathdate').text
      end

      def webpage
        xml.at_xpath('pgterms:agent/pgterms:webpage').attribute('resource').content
      end

      def aliases
        entries = Array.new
        xml.xpath('//pgterms:alias').each do |name|
          entries << name.text
        end
        entries
      end

    private

      def name_parts
        parts = xml.xpath('//pgterms:name').text.split(/, */)
        last  = parts.shift
        first = parts.reverse.join(' ')

        {first: first, last: last}
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gutenberg_rdf-0.0.2 lib/gutenberg_rdf/rdf/agent.rb