lib/ya2yaml.rb in ya2yaml-0.23 vs lib/ya2yaml.rb in ya2yaml-0.24

- old
+ new

@@ -1,8 +1,8 @@ #!/usr/bin/env ruby -# $Id: ya2yaml.rb,v 0.23 2006-09-14 05:42:04+09 funai Exp funai $ +# $Id: ya2yaml.rb,v 0.24 2006-11-06 01:15:07+09 funai Exp funai $ # # Author:: Akira FUNAI # Copyright:: Copyright (c) 2006 Akira FUNAI # License:: MIT License @@ -43,10 +43,21 @@ when 'Hash' if (obj.length == 0) '{}' else indent = "\n" + s_indent(level - 1) - obj.keys.sort {|x,y| x.to_s <=> y.to_s }.collect {|k| + hash_order = @options[:hash_order] + if (hash_order && level == 1) + hash_keys = obj.keys.sort {|x,y| + x_order = hash_order.index(x) ? hash_order.index(x) : Float::MAX + y_order = hash_order.index(y) ? hash_order.index(y) : Float::MAX + o = (x_order <=> y_order) + (o != 0) ? o : (x.to_s <=> y.to_s) + } + else + hash_keys = obj.keys.sort {|x,y| x.to_s <=> y.to_s } + end + hash_keys.collect {|k| key = emit(k,level + 1) if ( is_one_plain_line?(key) || key =~ /\A(#{REX_BOOL}|#{REX_FLOAT}|#{REX_INT}|#{REX_NULL})\z/x )