Class: Lutaml::Lml::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/lml/source.rb

Overview

Normalizes pipeline input (String, StringIO, File, Tempfile) behind one interface: full text, filesystem path (or nil), and the directory imports/includes resolve against.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Source

Returns a new instance of Source.



17
18
19
# File 'lib/lutaml/lml/source.rb', line 17

def initialize(input)
  @input = input
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



11
12
13
# File 'lib/lutaml/lml/source.rb', line 11

def input
  @input
end

Class Method Details

.wrap(input) ⇒ Object



13
14
15
# File 'lib/lutaml/lml/source.rb', line 13

def self.wrap(input)
  input.is_a?(Source) ? input : new(input)
end

Instance Method Details

#base_dirObject



34
35
36
# File 'lib/lutaml/lml/source.rb', line 34

def base_dir
  path ? File.dirname(path) : Dir.pwd
end

#pathObject

Filesystem path, or nil for anonymous input (String/StringIO).



29
30
31
32
# File 'lib/lutaml/lml/source.rb', line 29

def path
  io = unwrapped
  io.is_a?(File) ? io.path : nil
end

#readObject



21
22
23
24
25
26
# File 'lib/lutaml/lml/source.rb', line 21

def read
  return @input if @input.is_a?(String)

  @input.rewind
  @input.read
end