class Google::Maps::Place
Attributes
html[R]
keyword[R]
place_id[R]
text[R]
to_html[R]
to_s[R]
Public Class Methods
find(keyword, language = :en)
click to toggle source
# File lib/google_maps/place.rb, line 18 def self.find(keyword, language = :en) args = { language: language, input: keyword } API.query(:places_service, args).predictions.map { |prediction| Place.new(prediction, keyword) } end
new(data, keyword)
click to toggle source
# File lib/google_maps/place.rb, line 12 def initialize(data, keyword) @text = data.description @place_id = data.place_id @html = highligh_keywords(data, keyword) end
Private Instance Methods
highligh_keywords(data, keyword)
click to toggle source
# File lib/google_maps/place.rb, line 25 def highligh_keywords(data, keyword) keyword = Regexp.escape(keyword) matches = Array(keyword.scan(/\w+/)) html = data.description.dup matches.each do |match| html.gsub!(/(#{match})/i, '<strong>\1</strong>') end html end