class Parser::Psd2yaml
Public Class Methods
new(input, output)
click to toggle source
# File lib/psd2yaml.rb, line 8 def initialize(input, output) @output_file = output || File.basename(input, ".*") << ".yml" @psd = PSD.new(input) end
Public Instance Methods
parse()
click to toggle source
# File lib/psd2yaml.rb, line 13 def parse output = Hash.new @psd.parse! @psd.tree.descendant_layers.each do |layer| unless layer.text.nil? text = layer.text[:value].gsub(/\r?\n/, " ").split.join(" ") key = layer.name.downcase.gsub(/[^a-z0-9\s]/i, "").split.join("_") output[key] = text end end File.open(@output_file, "w") {|f| f.write(output.to_yaml line_width: -1)} puts "Created file #{@output_file}" end