Method: CiteProc::Asset#open

Defined in:
lib/citeproc/assets.rb

#open(input) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/citeproc/assets.rb', line 15

def open(input)
  case
  when input.respond_to?(:read)
    @location = nil
    @asset = input.read
  when input.to_s =~ /^\s*</
    @location = nil
    @asset = input.to_s.dup
  else
    case
    when File.exists?(input)
      @location = input
    when File.exists?(self.class.extend_name(input))
      @location = self.class.extend_name(input)
    when File.exists?(self.class.extend_path(input))
      @location = self.class.extend_path(input)
    else
      @location = input
    end

    Kernel.open(@location, 'r:UTF-8') do |io|
      @asset = io.read
    end
  end

  self
rescue => e
  raise ArgumentError, "failed to open asset #@location (#{input.inspect}): #{e.message}"
end