fork download
  1. require 'yaml'
  2.  
  3. class String
  4. def dequote
  5. return Integer( self ) rescue nil;
  6. return Float( self ) rescue nil;
  7. return self.sub( /^"(.*)"$/ ){ $1 };
  8. end
  9. end
  10.  
  11. print YAML.dump( STDIN.readlines.collect{|l|
  12. a = l.split( / *: */ ).map( &:dequote );
  13. { :name => a[0],
  14. :hw => a[1].split( / *; */ ).map{|x|
  15. a = x.split( / *, */ ).map( &:dequote );
  16. { :h => a[0], :w => a[1] } } };
  17. } );
  18.  
Success #stdin #stdout 0.04s 9312KB
stdin
"山田" : 173, 60 ; 176, 61
"佐藤" : 137, 40 ; 176, 16
stdout
---
- :name: 山田
  :hw:
  - :h: 173
    :w: 60
  - :h: 176
    :w: 61
- :name: 佐藤
  :hw:
  - :h: 137
    :w: 40
  - :h: 176
    :w: 16