Class: Mods::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/mods/reader.rb

Instance Method Summary collapse

Constructor Details

#initializeReader



6
7
# File 'lib/mods/reader.rb', line 6

def initialize
end

Instance Method Details

#from_file(filename, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML) ⇒ Object

Read in the contents of a Mods record from a file.

Examples:

foo = Mods::Reader.new.from_file('/path/to/mods/file.xml')


30
31
32
33
34
# File 'lib/mods/reader.rb', line 30

def from_file(filename, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML)
  File.open(filename) do |file|
    Nokogiri::XML(file)
  end
end

#from_nk_node(node) ⇒ Object



38
39
40
# File 'lib/mods/reader.rb', line 38

def from_nk_node(node)
  Nokogiri::XML(node.to_s, nil, node.document.encoding)
end

#from_str(str) ⇒ Object



11
12
13
# File 'lib/mods/reader.rb', line 11

def from_str(str)
  Nokogiri::XML(str, nil, str.encoding.to_s)
end

#from_url(url, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML) ⇒ Object

Read in the contents of a Mods file from a url.

Examples:

foo = Mods::Reader.new.from_url('http://purl.stanford.edu/bb340tm8592.mods')


20
21
22
23
# File 'lib/mods/reader.rb', line 20

def from_url(url, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML)
  require 'open-uri'
  Nokogiri::XML(URI.open(url).read)
end