Module: CiteProc::Asset
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#asset ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute asset.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
Instance Method Summary collapse
Instance Attribute Details
#asset ⇒ Object (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 |
#location ⇒ Object (readonly)
Returns the value of attribute location.
9 10 11 |
# File 'lib/citeproc/assets.rb', line 9 def location @location end |
Instance Method Details
#inspect ⇒ Object
51 52 53 |
# File 'lib/citeproc/assets.rb', line 51 def inspect "#<CiteProc::#{self.class.name} #{name}>" end |
#name ⇒ Object
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.}" end |
#open? ⇒ Boolean
11 12 13 |
# File 'lib/citeproc/assets.rb', line 11 def open? !asset.nil? end |