Sha256: f826d7f71b14d1ef2447f307bad8c45e6395cc2402b9d49bbe96e2e791a4a703
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
module GutenbergRdf class Rdf class Agent attr_reader :xml attr_accessor :role def initialize(xml) @xml = xml end def to_s fullname end def id xml.attributes['about'].match(/\A\d\d\d\d\/agents\/(\d+)\z/)[1] end def role @role ||= 'oth' end def assign_role(roles) self.role = roles["#{id}"] end def fullname [firstname, lastname].reject(&:empty?).join(' ') end def lastname @lastname ||= name_parts[:last] end def firstname @firstname ||= name_parts[:first] end def birthdate xml.elements['pgterms:birthdate'].text end def deathdate xml.elements['pgterms:deathdate'].text end def webpage xml.elements['pgterms:webpage'].attributes['resource'] end def aliases entries = Array.new xml.elements.each('pgterms:alias') do |name| entries << name.text end entries end private def name_parts parts = xml.elements['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.3.1 | lib/gutenberg_rdf/rdf/agent.rb |