Class: Mods::Reader
- Inherits:
-
Object
- Object
- Mods::Reader
- Defined in:
- lib/mods/reader.rb
Instance Method Summary collapse
-
#from_file(filename, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML) ⇒ Object
Read in the contents of a Mods record from a file.
-
#from_nk_node(node) ⇒ Object
Nokogiri::XML::Document.
-
#from_str(str) ⇒ Object
Nokogiri::XML::Document.
-
#from_url(url, encoding = nil, options = Nokogiri::XML::ParseOptions::DEFAULT_XML) ⇒ Object
Read in the contents of a Mods file from a url.
-
#initialize ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize ⇒ Reader
Returns a new instance of Reader.
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.
30 31 32 33 34 |
# File 'lib/mods/reader.rb', line 30 def from_file(filename, encoding = nil, = Nokogiri::XML::ParseOptions::DEFAULT_XML) File.open(filename) do |file| Nokogiri::XML(file) end end |
#from_nk_node(node) ⇒ Object
Returns Nokogiri::XML::Document.
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
Returns Nokogiri::XML::Document.
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.
20 21 22 23 |
# File 'lib/mods/reader.rb', line 20 def from_url(url, encoding = nil, = Nokogiri::XML::ParseOptions::DEFAULT_XML) require 'open-uri' Nokogiri::XML(URI.open(url).read) end |