Last active
June 20, 2019 15:30
-
-
Save begin29/ad44d7db60581aa51aedc3d241be7506 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def match_urls_in_cities(file_names) | |
cities_count = {} | |
file_names.each do |file_name| | |
File.open(file_name, "r") do |f| | |
f.each_line do |line| | |
city_name = line.match(/(.*)\t/)[0].gsub("\t", "") | |
cities_count[city_name] ||= 0 | |
cities_count[city_name] += 1 if is_url_present?(line) | |
end | |
end | |
end | |
p cities_count | |
end | |
private | |
def is_url_present?(line) | |
line.match(/(http[s]?\:\/\/)[a-z0-9._]+/).tap do |matched_val| | |
return true if matched_val | |
end | |
return false | |
end | |
match_urls_in_cities(["tweets_aa", "tweets_ab", "tweets_ac"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment