Class: Cielo24::BaseOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/cielo24/options.rb

Direct Known Subclasses

CommonOptions, PerformTranscriptionOptions

Instance Method Summary collapse

Instance Method Details

#get_hashObject



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)
    if !value.nil?
      hash[var.to_s.delete("@")] = self.instance_variable_get(var)
    end
  }
  return hash
end

#populate_from_hash(hash) ⇒ Object



34
35
36
37
38
# File 'lib/cielo24/options.rb', line 34

def populate_from_hash(hash)
  hash.each do |key, value|
    populate_from_key_value_pair(key, value)
  end
end

#populate_from_key_value_pair(key, value) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/cielo24/options.rb', line 24

def populate_from_key_value_pair(key, value)
  # Iterate over instance variables
  self.instance_variables.each{ |var|
    if var.to_s.delete("@") == key
      self.instance_variable_set(var, value)
      break
    end
  }
end

#to_queryObject



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