Class: SimplyInlineSvg::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/simply_inline_svg/storage.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/simply_inline_svg/storage.rb', line 5

def data
  @data
end

Class Method Details

.find(name) ⇒ Object



26
27
28
# File 'lib/simply_inline_svg/storage.rb', line 26

def find(name)
  self.data[name]
end

.find!(name) ⇒ Object

Raises:



21
22
23
24
# File 'lib/simply_inline_svg/storage.rb', line 21

def find!(name)
  raise SvgNotFound if self.data[name].nil?
  self.data[name]
end

.register_directory(directory) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/simply_inline_svg/storage.rb', line 7

def register_directory(directory)
  fpaths = Dir["#{directory}/**/*.svg"]
  while fpaths.length > 0
    fpath = fpaths.shift
    register_svg(File.basename(fpath), fpath)
  end
  self.data
end

.register_svg(fname, fpath) ⇒ Object



16
17
18
19
# File 'lib/simply_inline_svg/storage.rb', line 16

def register_svg(fname, fpath)
  svg = Svg.new(File.read(fpath))
  self.data.merge!({ fname => svg })
end