Class: HelloGoodbye::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/hello_goodbye/json/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
# File 'lib/hello_goodbye/json/response.rb', line 5

def initialize(options={})
  options.map do |key,value|
    self.send("#{key}=".to_sym,value) if self.respond_to?("#{key}=".to_sym)
  end
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/hello_goodbye/json/response.rb', line 3

def message
  @message
end

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/hello_goodbye/json/response.rb', line 3

def results
  @results
end

#successObject

Returns the value of attribute success.



3
4
5
# File 'lib/hello_goodbye/json/response.rb', line 3

def success
  @success
end

Instance Method Details

#to_hashObject



23
24
25
26
27
28
29
30
# File 'lib/hello_goodbye/json/response.rb', line 23

def to_hash
  h = {
    "success" => self.success,
    "message" => self.message.to_s
  }
  h["results"] = self.results if !self.results.nil?
  h
end

#to_jsonObject



32
33
34
# File 'lib/hello_goodbye/json/response.rb', line 32

def to_json
  self.to_hash.to_json
end