Module: BibframeRuby

Defined in:
lib/bibframe_ruby.rb,
lib/bibframe_ruby/graph.rb,
lib/bibframe_ruby/parser.rb,
lib/bibframe_ruby/version.rb,
lib/bibframe_ruby/resource.rb,
lib/bibframe_ruby/models/hub.rb,
lib/bibframe_ruby/models/item.rb,
lib/bibframe_ruby/models/work.rb,
lib/bibframe_ruby/models/agent.rb,
lib/bibframe_ruby/models/title.rb,
lib/bibframe_ruby/graph_builder.rb,
lib/bibframe_ruby/models/person.rb,
lib/bibframe_ruby/marc_converter.rb,
lib/bibframe_ruby/models/subject.rb,
lib/bibframe_ruby/models/instance.rb,
lib/bibframe_ruby/models/contribution.rb,
lib/bibframe_ruby/models/organization.rb,
sig/bibframe_ruby.rbs

Overview

BibframeRuby::Organization: A BIBFRAME Organization agent

Defined Under Namespace

Classes: Agent, Contribution, Error, Graph, GraphBuilder, Hub, Instance, Item, MarcConverter, Organization, Parser, Person, Resource, Subject, Title, Work

Constant Summary collapse

VERSION =

Returns:

  • (String)
"0.2.2"

Class Method Summary collapse

Class Method Details

.convert_marc(path, baseuri: "http://example.org/", idsource: "http://id.loc.gov/vocabulary/organizations/dlc") ⇒ Object



38
39
40
41
42
# File 'lib/bibframe_ruby.rb', line 38

def self.convert_marc(path, baseuri: "http://example.org/", idsource: "http://id.loc.gov/vocabulary/organizations/dlc")
  input = File.read(path)
  rdfxml = MarcConverter.new(input, baseuri: baseuri, idsource: idsource).convert
  parse(rdfxml, format: :rdfxml)
end

.parse(input, format: :jsonld) ⇒ Object



26
27
28
29
# File 'lib/bibframe_ruby.rb', line 26

def self.parse(input, format: :jsonld)
  rdf_graph = Parser.new(input, format: format).parse
  Graph.from_rdf(rdf_graph)
end

.parse_file(path) ⇒ Object



31
32
33
34
35
36
# File 'lib/bibframe_ruby.rb', line 31

def self.parse_file(path)
  ext = File.extname(path)
  format = Parser.format_for_extension(ext)
  input = File.read(path)
  parse(input, format: format)
end

.parse_uri(uri, redirect_limit: 5) ⇒ Object

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/bibframe_ruby.rb', line 44

def self.parse_uri(uri, redirect_limit: 5)
  raise Error, "Too many redirects" if redirect_limit.zero?

  parsed_uri = URI.parse(uri)
  response = Net::HTTP.get_response(parsed_uri)

  if response.is_a?(Net::HTTPSuccess)
    ext = File.extname(parsed_uri.path)
    format = ext.empty? ? :jsonld : Parser.format_for_extension(ext)
    parse(response.body, format: format)
  elsif response.is_a?(Net::HTTPRedirection)
    parse_uri(response["location"], redirect_limit: redirect_limit - 1)
  else
    raise Error, "HTTP error: #{response.code} #{response.message}"
  end
end