Class: Parser::Psd2yaml
- Inherits:
-
Object
- Object
- Parser::Psd2yaml
- Defined in:
- lib/psd2yaml.rb
Instance Method Summary collapse
-
#initialize(input, output) ⇒ Psd2yaml
constructor
A new instance of Psd2yaml.
- #parse ⇒ Object
Constructor Details
#initialize(input, output) ⇒ Psd2yaml
Returns a new instance of Psd2yaml.
8 9 10 11 |
# File 'lib/psd2yaml.rb', line 8 def initialize(input, output) @output_file = output || File.basename(input, ".*") << ".yml" @psd = PSD.new(input) end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |