Class: YouGotListed::Complexes::SearchResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/you_got_listed/complexes.rb

Instance Attribute Summary collapse

Attributes inherited from Response

#ygl_response

Instance Method Summary collapse

Methods inherited from Response

#method_missing, #success?

Constructor Details

#initialize(response, client, limit = 20, raise_error = false) ⇒ SearchResponse

Returns a new instance of SearchResponse.



22
23
24
25
26
# File 'lib/you_got_listed/complexes.rb', line 22

def initialize(response, client, limit = 20, raise_error = false)
  super(response, raise_error)
  self.limit = limit
  self.client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class YouGotListed::Response

Instance Attribute Details

#clientObject

Returns the value of attribute client.



20
21
22
# File 'lib/you_got_listed/complexes.rb', line 20

def client
  @client
end

#limitObject

Returns the value of attribute limit.



20
21
22
# File 'lib/you_got_listed/complexes.rb', line 20

def limit
  @limit
end

Instance Method Details

#paginatorObject



44
45
46
47
48
49
50
51
# File 'lib/you_got_listed/complexes.rb', line 44

def paginator
  @paginator_cache ||= WillPaginate::Collection.create(
    (self.ygl_response.page_index ? self.ygl_response.page_index : 1),
    self.limit,
    (self.ygl_response.total ? self.ygl_response.total : properties.size)) do |pager|
    pager.replace property_complexes
  end
end

#property_complexesObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/you_got_listed/complexes.rb', line 28

def property_complexes
  @cached_property_complexes ||= begin
    props = []
    if self.success? && !self.ygl_response.complexes.blank?
      if self.ygl_response.complexes.complex.is_a?(Array)
        self.ygl_response.complexes.complex.each do |complex|
          props << YouGotListed::Complex.new(complex, self.client)
        end
      else
        props << YouGotListed::Complex.new(self.ygl_response.complexes.complex, self.client)
      end
    end
    props
  end
end