Last active
July 6, 2024 11:57
-
-
Save zavan/a5ff1d36fb8e347c57f0772d06e18b50 to your computer and use it in GitHub Desktop.
victor
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
require 'json' | |
response = %Q(Local = belo horizonte | |
Clima atual = Parcialmente nublado π€οΈ | |
Temperatura = +25Β°C | |
Umidade = 36% | |
Vento = β11km/h | |
Lua agora = π | |
Nascer do sol = 06:31:42 | |
Por do sol = 17:29:23) | |
moon_map = { | |
"π" => "nova", | |
"π" => "crescente", | |
"π" => "crescente", | |
"π" => "crescente", | |
"π" => "cheia", | |
"π" => "minguante", | |
"π" => "minguante", | |
"π" => "minguante", | |
"π" => "minguante" | |
} | |
hash = response.split("\n").map { |line| line.split(" = ") }.to_h.transform_keys { |key| key.gsub(" ", "_").downcase }.transform_keys(&:to_sym) | |
hash[:clima_atual] = hash[:clima_atual].split(" ")[0..-2].join("_").downcase.to_sym | |
hash[:temperatura] = hash[:temperatura].split("Β°")[0].to_f | |
hash[:umidade] = hash[:umidade].split("%")[0].to_f | |
hash[:vento] = hash[:vento].split("km/h")[0][1..-1].to_f | |
hash[:lua_agora] = moon_map[hash[:lua_agora]].to_sym | |
puts JSON.pretty_generate(hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment