Class: Harvestdor::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/harvestdor/client.rb

Overview

convenience methods for getting Nokogiri::XML::Document objects for pieces of the purl public xml, and errors when pieces are missing

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|config| ... } ⇒ Client

Initialize a new instance of Harvestdor::Client

Examples:

client = Harvestdor::Client.new(
  { # Example with all possible options
    :log_dir => File.join(File.dirname(__FILE__), "..", "logs"),
    :log_name => 'harvestdor.log',
    :purl => 'https://purl.stanford.edu'
  })

Parameters:

  • Hash

    options

Yields:



34
35
36
37
38
# File 'lib/harvestdor/client.rb', line 34

def initialize options = {}
  config.configure(YAML.load_file(options[:config_yml_path])) if options[:config_yml_path]
  config.configure options
  yield(config) if block_given?
end

Class Method Details

.default_configObject

Set default values for the construction of Harvestdor::Client objects



7
8
9
10
11
12
13
14
# File 'lib/harvestdor/client.rb', line 7

def self.default_config
  @class_config ||= Confstruct::Configuration.new(
    {
      :log_dir => LOG_DIR_DEFAULT,
      :log_name => LOG_NAME_DEFAULT,
      :purl => PURL_DEFAULT
    })
end

.logger(log_dir, log_name) ⇒ Object

Global, memoized, lazy initialized instance of a logger

Parameters:

  • log_dir (String)

    directory for to get log file

  • log_name (String)

    name of log file



19
20
21
22
# File 'lib/harvestdor/client.rb', line 19

def self.logger(log_dir, log_name)
  Dir.mkdir(log_dir) unless File.directory?(log_dir)
  @logger ||= Logger.new(File.join(log_dir, log_name), 'daily')
end

Instance Method Details

#configObject



40
41
42
# File 'lib/harvestdor/client.rb', line 40

def config
  @config ||= Confstruct::Configuration.new(self.class.default_config)
end

#content_metadata(object) ⇒ Nokogiri::XML::Document

the contentMetadata for this fedora object, from the purl xml

Parameters:

  • object (Object)

    a String containing a druid (e.g. ab123cd4567), or a Nokogiri::XML::Document containing the public_xml for an object

Returns:

  • (Nokogiri::XML::Document)

    the contentMetadata for the fedora object



66
67
68
# File 'lib/harvestdor/client.rb', line 66

def  object
  Harvestdor.(object, config.purl)
end

#dc(object) ⇒ Nokogiri::XML::Document

the Dublin Core for this fedora object, from the purl xml

Parameters:

  • object (Object)

    a String containing a druid (e.g. ab123cd4567), or a Nokogiri::XML::Document containing the public_xml for an object

Returns:

  • (Nokogiri::XML::Document)

    the dc for the fedora object



98
99
100
# File 'lib/harvestdor/client.rb', line 98

def dc object
  Harvestdor.dc(object, config.purl)
end

#identity_metadata(object) ⇒ Nokogiri::XML::Document

the identityMetadata for this fedora object, from the purl xml

Parameters:

  • object (Object)

    a String containing a druid (e.g. ab123cd4567), or a Nokogiri::XML::Document containing the public_xml for an object

Returns:

  • (Nokogiri::XML::Document)

    the identityMetadata for the fedora object



74
75
76
# File 'lib/harvestdor/client.rb', line 74

def  object
  Harvestdor.(object, config.purl)
end

#loggerObject



44
45
46
# File 'lib/harvestdor/client.rb', line 44

def logger
  @logger ||= self.class.logger(config.log_dir, config.log_name)
end

#mods(druid) ⇒ Nokogiri::XML::Document

the public xml for this fedora object, from the purl server

Parameters:

  • druid (String)

    e.g. ab123cd4567, in the purl url

Returns:

  • (Nokogiri::XML::Document)

    the MODS metadata for the fedora object



51
52
53
# File 'lib/harvestdor/client.rb', line 51

def mods druid
  Harvestdor.mods(druid, config.purl)
end

#public_xml(druid) ⇒ Nokogiri::XML::Document

the public xml for this fedora object, from the purl xml

Parameters:

  • druid (String)

    e.g. ab123cd4567, in the purl url

Returns:

  • (Nokogiri::XML::Document)

    the public xml for the fedora object



58
59
60
# File 'lib/harvestdor/client.rb', line 58

def public_xml druid
  Harvestdor.public_xml(druid, config.purl)
end

#rdf(object) ⇒ Nokogiri::XML::Document

the RDF for this fedora object, from the purl xml

Parameters:

  • object (Object)

    a String containing a druid (e.g. ab123cd4567), or a Nokogiri::XML::Document containing the public_xml for an object

Returns:

  • (Nokogiri::XML::Document)

    the RDF for the fedora object



90
91
92
# File 'lib/harvestdor/client.rb', line 90

def rdf object
  Harvestdor.rdf(object, config.purl)
end

#rights_metadata(object) ⇒ Nokogiri::XML::Document

the rightsMetadata for this fedora object, from the purl xml

Parameters:

  • object (Object)

    a String containing a druid (e.g. ab123cd4567), or a Nokogiri::XML::Document containing the public_xml for an object

Returns:

  • (Nokogiri::XML::Document)

    the rightsMetadata for the fedora object



82
83
84
# File 'lib/harvestdor/client.rb', line 82

def  object
  Harvestdor.(object, config.purl)
end