Module: Gattica::Convertible

Included in:
Account, Auth, DataPoint, DataSet, Segment, User
Defined in:
lib/gattica/convertible.rb

Overview

Common output methods that are sharable

Instance Method Summary collapse

Instance Method Details

#to_hObject

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_queryObject



23
24
25
# File 'lib/gattica/convertible.rb', line 23

def to_query
  to_h.to_query
end

#to_sObject 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_xmlObject

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