Skip to content

Instantly share code, notes, and snippets.

@zavan
Last active July 6, 2024 11:57
Show Gist options
  • Save zavan/a5ff1d36fb8e347c57f0772d06e18b50 to your computer and use it in GitHub Desktop.
Save zavan/a5ff1d36fb8e347c57f0772d06e18b50 to your computer and use it in GitHub Desktop.
victor
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