Class: RubyQL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ RubyQL

Returns a new instance of RubyQL.



7
8
9
10
11
12
13
14
15
# File 'lib/rubyql.rb', line 7

def initialize(params)
  if params.is_a?(JSON)
    @params = JSON.parse(params)
  elsif params.is_a?(Hash)
    @params = params
  else
    raise InitError, "Cant initialize with a #{params.class} please provide a valid JSON or Hash"
  end
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/rubyql.rb', line 5

def params
  @params
end

Instance Method Details

#executeObject



17
18
19
20
21
22
# File 'lib/rubyql.rb', line 17

def execute
  return {} if query.nil?
  query.select do |key, _value|
    response_attr.key? key
  end.merge query_params
end

#queryObject



36
# File 'lib/rubyql.rb', line 36

def query; end

#query_paramsObject



24
25
26
27
28
# File 'lib/rubyql.rb', line 24

def query_params
  @params.reject do |_key, value|
    value == '' || value.nil?
  end
end

#response_attrObject



30
31
32
33
34
# File 'lib/rubyql.rb', line 30

def response_attr
  @params.select do |_key, value|
    value == '' || value.nil?
  end
end