class GreetLocally::Translator
Attributes
geolocation_url[R]
language_url[R]
Public Class Methods
new(ip_address)
click to toggle source
# File lib/greet_locally/translator.rb, line 4 def initialize(ip_address) @geolocation_url = "https://ipinfo.io/#{ip_address}" #Gets IP for user @language_url = "https://restcountries.eu/rest/v2/alpha" end
Public Instance Methods
process()
click to toggle source
# File lib/greet_locally/translator.rb, line 9 def process say_hi(language) end
Private Instance Methods
language()
click to toggle source
# File lib/greet_locally/translator.rb, line 41 def language response = Net::HTTP.get(URI.parse("#{language_url}/#{location}")) JSON.parse(response)["languages"][0]["name"].downcase end
location()
click to toggle source
# File lib/greet_locally/translator.rb, line 36 def location response = Net::HTTP.get(URI.parse(geolocation_url)) JSON.parse(response)["country"].downcase end
say_hi(language = "english")
click to toggle source
# File lib/greet_locally/translator.rb, line 17 def say_hi(language = "english") case language.downcase when "spanish" "Hola Mundo!" when "chinese" "你好,世界!" when "japanese" "こんにちは世界!" when "german" "Hallo Welt!" when "hindi" "नमस्ते दुनिया!" when "russian" "Привет мир!" else "Hello world!" end end