Class: RubyQL
- Inherits:
-
Object
- Object
- RubyQL
- Defined in:
- lib/rubyql.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(params) ⇒ RubyQL
constructor
A new instance of RubyQL.
- #query ⇒ Object
- #query_params ⇒ Object
- #response_attr ⇒ Object
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
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/rubyql.rb', line 5 def params @params end |
Instance Method Details
#execute ⇒ Object
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 |
#query ⇒ Object
36 |
# File 'lib/rubyql.rb', line 36 def query; end |
#query_params ⇒ Object
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_attr ⇒ Object
30 31 32 33 34 |
# File 'lib/rubyql.rb', line 30 def response_attr @params.select do |_key, value| value == '' || value.nil? end end |