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.



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

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/ea/svg/parity/source.rb', line 17

def path
  @path
end

Class Method Details

.detect(path) ⇒ Object



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

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

Instance Method Details

#documentObject



36
37
38
# File 'lib/ea/svg/parity/source.rb', line 36

def document
  load
end

#formatObject



40
41
42
# File 'lib/ea/svg/parity/source.rb', line 40

def format
  self.class.detect(path)
end

#loadObject



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

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