Class: Transdifflation::YAMLWriter
- Inherits:
-
Object
- Object
- Transdifflation::YAMLWriter
- Defined in:
- lib/transdifflation/yaml_writer.rb
Overview
Writes YAML
Class Method Summary collapse
-
.to_yaml(hash) ⇒ Object
Method used to prettify generated YAML.
Class Method Details
.to_yaml(hash) ⇒ Object
Method used to prettify generated YAML
7 8 9 10 11 12 13 14 15 |
# File 'lib/transdifflation/yaml_writer.rb', line 7 def self.to_yaml(hash) method = hash.respond_to?(:ya2yaml) ? :ya2yaml : :to_yaml string = hash.deep_stringify_keys.send(method) yaml_string = string.gsub("!ruby/symbol ", ":").sub("---","") yaml_string = yaml_string.gsub(/(\?) "([\w\s\\]+)"\n/) do |match| #Regex ? "es" \n match.sub(/\?\s+/, "").chomp end yaml_string = yaml_string.split("\n").map(&:rstrip).join("\n").strip end |