Class: Cielo24::BaseOptions
- Inherits:
-
Object
- Object
- Cielo24::BaseOptions
show all
- Defined in:
- lib/cielo24/options.rb
Instance Method Summary
collapse
Instance Method Details
#get_hash ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/cielo24/options.rb', line 4
def get_hash
hash = {}
self.instance_variables.each{ |var|
value = self.instance_variable_get(var)
unless value.nil?
hash[var.to_s.delete('@')] = value
end
}
return hash
end
|
#populate_from_hash(hash) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/cielo24/options.rb', line 35
def populate_from_hash(hash)
unless hash.nil?
hash.each do |key, value|
populate_from_key_value_pair(key, value)
end
end
end
|
#populate_from_key_value_pair(key, value) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/cielo24/options.rb', line 24
def populate_from_key_value_pair(key, value)
self.instance_variables.each{ |var|
if var.to_s.delete('@') == key.to_s
self.instance_variable_set(var, value)
break
end
}
end
|
#to_query ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/cielo24/options.rb', line 15
def to_query
hash = get_hash
array = Array.new
hash.each do |key, value|
array.push(key + '=' + value.to_s)
end
return array.join('&')
end
|