Method: JSON::Editor.model2data
- Defined in:
- lib/json/editor.rb
.model2data(iter) ⇒ Object
Convert the tree model starting from Gtk::TreeIter iter into a Ruby data structure and return it.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/json/editor.rb', line 82 def Editor.model2data(iter) return nil if iter.nil? case iter.type when 'Hash' hash = {} iter.each { |c| hash[c.content] = Editor.model2data(c.first_child) } hash when 'Array' array = Array.new(iter.n_children) iter.each_with_index { |c, i| array[i] = Editor.model2data(c) } array when 'Key' iter.content when 'String' iter.content when 'Numeric' content = iter.content if /\./.match(content) content.to_f else content.to_i end when 'TrueClass' true when 'FalseClass' false when 'NilClass' nil else fail "Unknown type found in model: #{iter.type}" end end |