module MapsFuelCommand
Constants
- SET_FUEL_PATTERN
- SET_FUEL_PREFIX
Public Instance Methods
Source
# File lib/maps_fuel_command.rb, line 32 def handle(text, network:, nick:, store: RabbotDb) parsed = parse_request(text) case parsed[:action] when :set_fuel DistanceFuelStore.set(network: network, nick: nick, consumption: parsed[:consumption], store: store) { reply: set_fuel_reply(parsed[:consumption]) } when :set_fuel_error { error: "Usage: !maps set fuel <L/100km>" } end end
Source
# File lib/maps_fuel_command.rb, line 18 def parse_request(text) text = text.to_s.strip if (match = text.match(SET_FUEL_PATTERN)) return { action: :set_fuel, consumption: match[1].to_f } end return { action: :set_fuel_error } if text.match?(SET_FUEL_PREFIX) { action: :route } end
Source
# File lib/maps_fuel_command.rb, line 28 def set_fuel_reply(consumption) IrcFormat.accent_paren("Fuel economy saved — #{consumption} L/100km") end