class Object
Constants
- NO_CHANGE
Public Instance Methods
main()
click to toggle source
# File lib/dy.rb, line 146 def main src, dst, options = read_arguments hash = Processor.new(source_file: src).hash File.write(dst, "#{options[:prefix] + "\n" if options[:prefix]}#{hash.to_yaml}") end
read_arguments()
click to toggle source
# File lib/dy.rb, line 128 def read_arguments options = {} OptionParser.new do |opts| opts.banner = "Usage: test.rb [options]" opts.on("-pPREFIX", "--prefix=PREFIX", "Prefix for the yaml output") do |v| options[:prefix] = v end end.parse! src, dst, *more = ARGV if src.nil? || dst.nil? || !more.empty? raise "Need two arguments" end [src, dst, options] end
read_file(filename, erb: false, args: {})
click to toggle source
# File lib/dy.rb, line 118 def read_file(filename, erb: false, args: {}) content = File.read(filename) if erb renderer = ERB.new(content) renderer.result(OpenStruct.new(args).instance_eval { binding }) else content end end
splice_array!(array)
click to toggle source
# File lib/dy.rb, line 104 def splice_array!(array) index = 0 while index < array.length do value = array[index] if value.is_a?(Splice) raise "Cannot splice except arrays" unless value.array.is_a?(Array) array[index, 1] = value.array index += value.array.length else index += 1 end end end