class MAndM::Cli

Attributes

preferences[R]

Public Class Methods

new() click to toggle source
# File lib/m_and_m/cli.rb, line 9
def initialize
  @preferences = MAndM::Preferences.new '.m_and_m'
end

Public Instance Methods

execute(*args) click to toggle source
# File lib/m_and_m/cli.rb, line 13
def execute *args
  command = args.shift
  command = :list unless command
  send command, *args
end
list() click to toggle source
# File lib/m_and_m/cli.rb, line 19
def list
  server.messages.each do |message|
    puts "#{c :yellow, time(message["at"])} #{c :magenta, message["from"]} said #{c :green, message["message"]}"
  end
end
say(who, message_id) click to toggle source
# File lib/m_and_m/cli.rb, line 25
def say who, message_id
  server.say uuid_for(who), message_id
end

Private Instance Methods

c(colour, text) click to toggle source
# File lib/m_and_m/cli.rb, line 39
def c colour, text
  text.to_s.foreground colour
end
server() click to toggle source
# File lib/m_and_m/cli.rb, line 31
def server
  MAndM::Server.new url, preferences
end
time(at) click to toggle source
# File lib/m_and_m/cli.rb, line 35
def time at
  Time.at(at).strftime("%d/%b %H:%M:%S")
end
url() click to toggle source
# File lib/m_and_m/cli.rb, line 47
def url
  preferences.ask :url, 'What is the server url'
end
uuid_for(name) click to toggle source
# File lib/m_and_m/cli.rb, line 43
def uuid_for name
  preferences.ask "#{name}_uuid".to_sym, "What is the uuid for #{name}"
end