Class: GameIcons::Icon
- Inherits:
-
Object
- Object
- GameIcons::Icon
- Defined in:
- lib/game_icons/icon.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#correct_pathdata ⇒ Object
Fix an incompatibility issue with Gimp & Inkscape Replaces path strings like “1.5-1.5” with “1.5 -1.5”.
-
#initialize(file) ⇒ Icon
constructor
A new instance of Icon.
-
#recolor(bg: '#000', fg: '#fff', bg_opacity: "1.0", fg_opacity: "1.0") ⇒ Object
Modify the background and foreground colors and their opacities.
- #string ⇒ Object
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
#file ⇒ Object (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_pathdata ⇒ Object
Fix an incompatibility issue with Gimp & Inkscape Replaces path strings like “1.5-1.5” with “1.5 -1.5”
29 30 31 32 33 34 35 36 |
# File 'lib/game_icons/icon.rb', line 29 def correct_pathdata 10.times do # this is a bit of a hack b/c my regex isn't perfect @svgstr = self.string .gsub(/(\d)\-/,'\1 -') # separate negatives .gsub(/(\.)(\d+)(\.)/,'\1\2 \3') # separate multi-decimals end self 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 |
# 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 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 |
#string ⇒ Object
11 12 13 |
# File 'lib/game_icons/icon.rb', line 11 def string @svgstr ||= File.open(@file) { |f| f.read } end |