Class: GameIcons::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/game_icons/icon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Icon

Returns a new instance of Icon.



7
8
9
# File 'lib/game_icons/icon.rb', line 7

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/game_icons/icon.rb', line 5

def file
  @file
end

Instance Method Details

#correct_pathdataObject

Fix an incompatibility issue with Gimp & Inkscape Replaces path strings like “1.5-1.5” with “1.5 -1.5”



31
32
33
# File 'lib/game_icons/icon.rb', line 31

def correct_pathdata
  raise 'DEPRECATED correct_pathdata is no longer necessary'
end

#recolor(bg: '#000', fg: '#fff', bg_opacity: "1.0", fg_opacity: "1.0") ⇒ Object

Modify the background and foreground colors and their opacities



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/game_icons/icon.rb', line 16

def recolor(bg: '#000', fg: '#fff', bg_opacity: "1.0", fg_opacity: "1.0")
  OptionalDeps.require_nokogiri
  bg.prepend('#') unless bg.start_with? '#'
  fg.prepend('#') unless fg.start_with? '#'
  doc     = Nokogiri::XML(self.string)
  doc.css('path')[0]['fill'] = bg # dark backdrop
  doc.css('path')[1]['fill'] = fg # light drawing
  doc.css('path')[0]['fill-opacity'] = bg_opacity.to_s # dark backdrop
  doc.css('path')[1]['fill-opacity'] = fg_opacity.to_s # light drawing
  @svgstr = doc.to_xml
  self
end

#stringObject



11
12
13
# File 'lib/game_icons/icon.rb', line 11

def string
  @svgstr ||= File.open(@file) { |f| f.read }
end