Module: SAXMachine

Overview

Mixup the mixin - to add functionality for simplifying results down to a hash

Instance Method Summary collapse

Instance Method Details

#to_hashObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pepper/stanzas/sax_machinery.rb', line 5

def to_hash
  convert = Proc.new {|v| 
    if v.methods.include? "to_hash"
      v.to_hash
    elsif v.is_a? Array
      v.map {|e| convert.call e }
    else
      v
    end
  }
  
  instance_variables.inject({}) do |h,v|
    h.merge v.gsub("@","") => convert.call( instance_variable_get v )
  end
end