Thor
# File lib/tamagoya/cli.rb, line 15 def menu(date = nil) if date.nil? date = Time.now.strftime("%H").to_i > BORDER_TIME ? (Date.today+1).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") else begin date_format = Date.parse(date) if date_format.nil? say('【ERROR】date format valid', :red) exit end rescue say('【ERROR】date format valid', :red) exit end end uri = URI.parse("http://tamagoya.anemone.link/api/v1/menus?date=#{date}") body = Net::HTTP.get(uri) json_obj = ActiveSupport::JSON.decode(body) if json_obj.nil? say('【ERROR】Menu not found', :red) exit end msg = "【#{json_obj['date']} のメニュー】\n" json_obj['menus'].each{|menu| if menu['maindish'] msg << "■■■#{menu['name']}■■■\n" else msg << "#{menu['name']}\n" end } detail = json_obj['detail'][0] msg << "【カロリー:#{detail['calorie']} kcal, 塩分:#{detail['salt']}g】" say(msg) end