Class: CS::CouchSearch
- Inherits:
-
Object
- Object
- CS::CouchSearch
- Defined in:
- lib/csapi/search.rb
Constant Summary collapse
- @@instance =
nil
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#results ⇒ Object
Returns the value of attribute results.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options = {}) ⇒ CouchSearch
constructor
A new instance of CouchSearch.
- #more ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CouchSearch
Returns a new instance of CouchSearch.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/csapi/search.rb', line 13 def initialize ={} defaults = { location: nil, gender: nil, :'has-photo' => nil, :'member-type' => 'host' , vouched: nil, verified: nil, network: nil, :'min-age' => nil, :'max-age' => nil, :platform => 'android' } @options = .merge(defaults) @@instance = self end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/csapi/search.rb', line 4 def @options end |
#results ⇒ Object
Returns the value of attribute results.
4 5 6 |
# File 'lib/csapi/search.rb', line 4 def results @results end |
Class Method Details
.instance ⇒ Object
9 10 11 |
# File 'lib/csapi/search.rb', line 9 def self.instance @@instance end |
Instance Method Details
#execute ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/csapi/search.rb', line 33 def execute html = HTTP.get('/msearch', :query => @options) doc = Nokogiri::HTML(html); users = {} statuses = { 'M' => 'maybe', 'T' => 'travelling', 'Y' => 'available', 'N' => 'unavailable' } doc.xpath('//article').each do |article| id = article.at_css('a').attr('href').split('/').last user = { string_id: article.attr('rel'), name: article.children.at_css("h2").content, location: article.children.at_css("div.location").content, status: statuses[article['class'].match(/couch-([A-Z])/)[1]], pic: article.at_css('img').attr('src') } users[id] = user end @results = CS::SearchResults.new(users) @results end |
#more ⇒ Object
60 61 62 63 64 |
# File 'lib/csapi/search.rb', line 60 def more @options[:page] = (@options[:page]||0)+1 @options[:exclude_ids] = results.collect {|k, u| u[:string_id]} results end |