class Ruboty::RecordDate::Actions::RecordDate
Constants
- NAMESPACE
Public Instance Methods
delete()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 25 def delete date = date_string(message[:date]) message.reply("Invalid date `#{date}`") and return unless date message.reply("No record in `#{date}`") and return unless recorded[date] if body = recorded[date][message[:time]] recorded[date].delete(message[:time]) message.reply("`#{body}` deleted.") else message.reply("Not exists time `#{message[:time]}`") end end
list()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 14 def list date = date_string(message[:date]) message.reply("Invalid date `#{date}`") and return unless date if recorded[date] message.reply(recorded[date].map{|time, body| "(#{time}) #{body}"}.join("\n")) else message.reply("Not recorded in `#{date}`") end end
record()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 9 def record time = add(body) message.reply("Recorded! time: #{time} body: `#{body}`") end
Private Instance Methods
add(body)
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 48 def add(body) time = Time.now.strftime('%T:%3N') recorded[today] ||= {} recorded[today][time] = body time end
body()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 44 def body message.body.gsub(/#{message.match_data}/, '').strip end
date_string(date)
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 59 def date_string(date) Date.parse(date).to_s.gsub(/-/, '/') rescue false end
recorded()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 40 def recorded message.robot.brain.data[NAMESPACE] ||= {} end
today()
click to toggle source
# File lib/ruboty/record_date/actions/record_date.rb, line 55 def today date_string(Date.today.to_s) end