Class: GeoScraper

Inherits:
Object
  • Object
show all
Defined in:
lib/GeoScraper/core.rb,
lib/GeoScraper/yelp.rb,
lib/GeoScraper/gnavi.rb,
lib/GeoScraper/tabelog.rb,
lib/GeoScraper/version.rb,
lib/GeoScraper/foursquare.rb,
lib/GeoScraper/sanzeromin.rb

Defined Under Namespace

Modules: FourSquare, Gnavi, SanzeroMin, Tabelog, Yelp

Constant Summary collapse

VERSION =
"0.0.1"
@@pattern =
[]

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ GeoScraper

Returns a new instance of GeoScraper.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/GeoScraper/core.rb', line 11

def initialize url
  @url = url
  @@pattern.each do |pattern|
    if @matches = pattern[0].match(@url)
      extend Object.const_get("GeoScraper::" + pattern[1])
      @matches = Regexp.last_match
      @result = scrape
      break
    end
  end
end

Instance Method Details

#get_doc(uri) ⇒ Object



23
24
25
# File 'lib/GeoScraper/core.rb', line 23

def get_doc uri
  Nokogiri::HTML.parse(open(uri, "User-Agent" => "Mozilla/5.0 Geo Scraper").read)
end

#has_data?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/GeoScraper/core.rb', line 27

def has_data?
  !@result.nil?
end

#latObject



37
38
39
40
41
# File 'lib/GeoScraper/core.rb', line 37

def lat
  if  has_data?
    @result["latitude"].to_f
  end
end

#lonObject



31
32
33
34
35
# File 'lib/GeoScraper/core.rb', line 31

def lon
  if  has_data?
    @result["longitude"].to_f
  end
end