Sha256: d03557acd4742d555a10bca5273480a5fb601bb2c24f8684661872c6a6347e67

Contents?: true

Size: 1.18 KB

Versions: 61

Compression:

Stored size: 1.18 KB

Contents

class Knj::Degulesider
  def initialize(args = {})
    @args = args
    @http = Knj::Http.new(
      "host" => "www.degulesider.dk"
    )
  end
  
  def search(sargs)
    url = "/search/#{Knj::Php.urlencode(sargs[:where])}/-/1/"
    
    html = @http.get(url)
    ret = []
    
    tbody_match = html["data"].match(/<tbody class='resultBody([\s\S]+?)<\/tbody>/)
    tbody_match[1].scan(/<tr id='res(\d+)'([\s\S]+?)<\/tr>/) do |match|
      res = {}
      
      if title_match = match[1].match(/<h2><a\s+class="fn".*>(.+)<\/a><\/h2>/)
        res[:name] = title_match[1]
      end
      
      if phone_match = match[1].match(/<div class="phones"><ul class="linkList"><li>(Mob.|)\s*([\d\s]+)<\/li><\/ul><\/div>/)
        if phone_match[1] == "Mob."
          res[:mobile] = phone_match[2].gsub(/\s+/, "")
        else
          raise "No such phone-mode: #{phone_match[1]}"
        end
      end
      
      if city_match = match[1].match(/'locality'>(.+)<\/span>/)
        res[:city] = city_match[1]
      end
      
      if category_match = match[1].match(/class='categoryLink'>(.+)<\/a>/)
        res[:category] = category_match[1]
      end
      
      ret << res
    end
    
    return ret
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
knjrbfw-0.0.72 lib/knj/degulesider.rb
knjrbfw-0.0.71 lib/knj/degulesider.rb
knjrbfw-0.0.70 lib/knj/degulesider.rb
knjrbfw-0.0.69 lib/knj/degulesider.rb
knjrbfw-0.0.68 lib/knj/degulesider.rb
knjrbfw-0.0.67 lib/knj/degulesider.rb
knjrbfw-0.0.66 lib/knj/degulesider.rb
knjrbfw-0.0.65 lib/knj/degulesider.rb
knjrbfw-0.0.64 lib/knj/degulesider.rb
knjrbfw-0.0.63 lib/knj/degulesider.rb
knjrbfw-0.0.62 lib/knj/degulesider.rb
knjrbfw-0.0.59 lib/knj/degulesider.rb
knjrbfw-0.0.58 lib/knj/degulesider.rb
knjrbfw-0.0.57 lib/knj/degulesider.rb
knjrbfw-0.0.55 lib/knj/degulesider.rb
knjrbfw-0.0.54 lib/knj/degulesider.rb
knjrbfw-0.0.53 lib/knj/degulesider.rb
knjrbfw-0.0.52 lib/knj/degulesider.rb
knjrbfw-0.0.51 lib/knj/degulesider.rb
knjrbfw-0.0.50 lib/knj/degulesider.rb