Sha256: 636f9c748128b9ff8d8ec541c239db68baf7203b63ac5b075b18e02988d79b7d

Contents?: true

Size: 1.18 KB

Versions: 40

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/#{Php4r.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

40 entries across 40 versions & 1 rubygems

Version Path
knjrbfw-0.0.94 lib/knj/degulesider.rb
knjrbfw-0.0.93 lib/knj/degulesider.rb
knjrbfw-0.0.92 lib/knj/degulesider.rb
knjrbfw-0.0.91 lib/knj/degulesider.rb
knjrbfw-0.0.90 lib/knj/degulesider.rb
knjrbfw-0.0.89 lib/knj/degulesider.rb
knjrbfw-0.0.88 lib/knj/degulesider.rb
knjrbfw-0.0.87 lib/knj/degulesider.rb
knjrbfw-0.0.86 lib/knj/degulesider.rb
knjrbfw-0.0.85 lib/knj/degulesider.rb
knjrbfw-0.0.84 lib/knj/degulesider.rb
knjrbfw-0.0.83 lib/knj/degulesider.rb
knjrbfw-0.0.82 lib/knj/degulesider.rb
knjrbfw-0.0.81 lib/knj/degulesider.rb
knjrbfw-0.0.80 lib/knj/degulesider.rb
knjrbfw-0.0.79 lib/knj/degulesider.rb
knjrbfw-0.0.78 lib/knj/degulesider.rb
knjrbfw-0.0.77 lib/knj/degulesider.rb
knjrbfw-0.0.75 lib/knj/degulesider.rb
knjrbfw-0.0.74 lib/knj/degulesider.rb