class Ruboty::Actions::JapanWeather
Public Instance Methods
call()
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 4 def call message.reply(forecast) end
Private Instance Methods
cmd?(captures)
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 32 def cmd?(captures) captures[1..2] if captures[1] && captures[2] end
convert(day)
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 40 def convert(day) case day when /今日|きょう|今|いま/u :today when /明日|あした/u :tomorrow when /明後日|あさって/u :day_after_tomorrow else day end end
forecast()
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 10 def forecast if captures = cmd?(message.match_data.captures) look_by_cmd(*captures).to_s elsif body = jp?(message.match_data.captures) look_by_jp(body).to_s else message.reply('Unmatched...') end end
jp?(captures)
click to toggle source
look_by_cmd(place, day)
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 20 def look_by_cmd(place, day) WeatherJp.get(place, convert(day)) rescue WeatherJp::WeatherJpError => e "Error: #{e}" end
look_by_jp(body)
click to toggle source
# File lib/ruboty/actions/japan_weather.rb, line 26 def look_by_jp(body) WeatherJp.parse(body) rescue WeatherJp::WeatherJpError => e "Error: #{e}" end