Module: CiteProc::Asset

Included in:
Locale, Style
Defined in:
lib/citeproc/assets.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#assetObject (readonly) Also known as: to_s

Returns the value of attribute asset.



9
10
11
# File 'lib/citeproc/assets.rb', line 9

def asset
  @asset
end

#locationObject (readonly)

Returns the value of attribute location.



9
10
11
# File 'lib/citeproc/assets.rb', line 9

def location
  @location
end

Instance Method Details

#inspectObject



51
52
53
# File 'lib/citeproc/assets.rb', line 51

def inspect
  "#<CiteProc::#{self.class.name} #{name}>"
end

#nameObject



45
46
47
# File 'lib/citeproc/assets.rb', line 45

def name
  File.basename(location, self.class.extension).sub(Regexp.new("^#{self.class.prefix}"), '')
end

#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

#open?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/citeproc/assets.rb', line 11

def open?
  !asset.nil?
end