Class: Inflect::Response

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

Overview

Responsible of encapsulate all the content of the service response

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, description = {}) ⇒ Inflect::Response

Parameters:

  • content (String, Hash) (defaults to: nil)

    The response of the service. Required.

  • description (Hash) (defaults to: {})

    Contains all the description of service response.

Options Hash (description):

  • :served_by (Class)

    Handler Service. Instance of AbstractService. Required.

  • :query_words (Array<String>)

    The list of words received on the request. Required.

  • :handled_word (String)

    The handled word by the service. Required.


15
16
17
18
19
20
# File 'lib/inflect/response.rb', line 15

def initialize(content=nil, description={})
  @content        =   content
  @timestamp      =   Time.now
  @errors         =   {}
  @attributes     =   extract_attributes(description)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes


7
8
9
# File 'lib/inflect/response.rb', line 7

def attributes
  @attributes
end

#contentObject (readonly)

Returns the value of attribute content


7
8
9
# File 'lib/inflect/response.rb', line 7

def content
  @content
end

#errorsObject (readonly)

Returns the value of attribute errors


7
8
9
# File 'lib/inflect/response.rb', line 7

def errors
  @errors
end

#timestampObject (readonly)

Returns the value of attribute timestamp


7
8
9
# File 'lib/inflect/response.rb', line 7

def timestamp
  @timestamp
end

Class Method Details

.attribute_keysObject


22
23
24
# File 'lib/inflect/response.rb', line 22

def self.attribute_keys
  @@attribute_keys = [:served_by, :query_words]
end

Instance Method Details

#valid?true, false

Validates required attributes for a valid response.

Returns:

  • (true, false)

39
40
41
42
43
# File 'lib/inflect/response.rb', line 39

def valid?
  private_methods.grep(/valid_attribute/).collect do |method_name|
    self.send method_name
  end.all?
end