Class: Ea::Svg::Parity::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/parity/source.rb

Overview

Loads an EA model Document from any supported source file (.qea, .xmi). Used by the bench task to keep file-format dispatch in one place.

Constant Summary collapse

EXTENSIONS =
{
  ".qea" => :qea,
  ".xmi" => :xmi
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Source

Returns a new instance of Source.



21
22
23
# File 'lib/ea/svg/parity/source.rb', line 21

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



19
20
21
# File 'lib/ea/svg/parity/source.rb', line 19

def path
  @path
end

Class Method Details

.detect(path) ⇒ Object



25
26
27
28
29
# File 'lib/ea/svg/parity/source.rb', line 25

def self.detect(path)
  ext = File.extname(path).downcase
  EXTENSIONS[ext] ||
    raise(ArgumentError, "unsupported source: #{path} (ext=#{ext})")
end

Instance Method Details

#documentObject



38
39
40
# File 'lib/ea/svg/parity/source.rb', line 38

def document
  load
end

#formatObject



42
43
44
# File 'lib/ea/svg/parity/source.rb', line 42

def format
  self.class.detect(path)
end

#loadObject



31
32
33
34
35
36
# File 'lib/ea/svg/parity/source.rb', line 31

def load
  case self.class.detect(path)
  when :qea then load_qea
  when :xmi then load_xmi
  end
end