Module: Gattica::Convertible
- Defined in:
- lib/gattica/convertible.rb
Overview
Common output methods that are sharable
Instance Method Summary collapse
-
#to_h ⇒ Object
output as hash.
- #to_query ⇒ Object
-
#to_s ⇒ Object
(also: #inspect)
output nice inspect syntax.
-
#to_xml ⇒ Object
Return the raw XML (if the object has a @xml instance variable, otherwise convert the object itself to xml).
Instance Method Details
#to_h ⇒ Object
output as hash
8 9 10 11 12 13 14 |
# File 'lib/gattica/convertible.rb', line 8 def to_h output = {} instance_variables.each do |var| output.merge!({ var[1..-1] => instance_variable_get(var) }) unless var == '@xml' # exclude the whole XML dump end output.tap { |h| h.include? HashExtensions } end |
#to_query ⇒ Object
23 24 25 |
# File 'lib/gattica/convertible.rb', line 23 def to_query to_h.to_query end |
#to_s ⇒ Object Also known as: inspect
output nice inspect syntax
17 18 19 |
# File 'lib/gattica/convertible.rb', line 17 def to_s to_h.inspect end |
#to_xml ⇒ Object
Return the raw XML (if the object has a @xml instance variable, otherwise convert the object itself to xml)
28 29 30 31 32 33 34 |
# File 'lib/gattica/convertible.rb', line 28 def to_xml if @xml @xml else self.to_xml end end |