Skip to content

Commit

Permalink
Refactor #autor and #editor using #agent and #create_agent
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaier committed Jan 19, 2014
1 parent fd26ab1 commit c7efc9d
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/bibtex/entry/rdf_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,7 @@ def author
graph << [entry, bibo[:authorList], seq]

bibtex[:author].each do |name|
node = RDF::Node.new

graph << [node, RDF.type, RDF::FOAF[:Person]]

if name.is_a?(BibTeX::Name)
[:given, :family, :prefix, :suffix].each do |part|
graph << [node, bibo["#{part}Name"], name.send(part).to_s] unless name.send(part).nil?
end
else
graph << [node, RDF::FOAF.name, name.to_s]
end
node = agent(name) { create_agent(name, :Person) }

graph << [entry, RDF::DC.creator, node]
graph << [seq, RDF.li, node]
Expand Down Expand Up @@ -125,17 +115,7 @@ def editor
graph << [entry, bibo[:editorList], seq]

bibtex[:editor].each do |name|
node = RDF::Node.new

graph << [node, RDF.type, RDF::FOAF[:Person]]

if name.is_a?(BibTeX::Name)
[:given, :family, :prefix, :suffix].each do |part|
graph << [node, bibo["#{part}Name"], name.send(part).to_s] unless name.send(part).nil?
end
else
graph << [node, RDF::FOAF.name, name.to_s]
end
node = agent(name) { create_agent(name, :Person) }

graph << [entry, bibo.name, node]
graph << [seq, RDF.li, node]
Expand Down Expand Up @@ -370,6 +350,25 @@ def graph
@graph ||= RDF::Graph.new
end

def agent(key, &block)
@agent ||= {}
@agent[key] ||= yield
end

def create_agent(name, type)
node = RDF::Node.new

graph << [node, RDF.type, RDF::FOAF[type]]
graph << [node, RDF::FOAF.name, name.to_s]

if name.is_a?(BibTeX::Name)
[:given, :family, :prefix, :suffix].each do |part|
graph << [node, bibo["#{part}Name"], name.send(part).to_s] unless name.send(part).nil?
end

node
end

def remove_from_fallback(*fields)
@fallback ||= bibtex.fields.keys

Expand Down

0 comments on commit c7efc9d

Please sign in to comment.