Class: BubBot::Slack::Command::Claim
- Inherits:
-
BubBot::Slack::Command
- Object
- BubBot::Slack::Command
- BubBot::Slack::Command::Claim
- Includes:
- ActionView::Helpers::DateHelper
- Defined in:
- lib/bub_bot/slack/commands/claim.rb
Constant Summary collapse
- DEFAULT_DURATION =
1.hour.freeze
- INCREMENTS =
%w(minute hour day week month)
Class Method Summary collapse
-
.aliases ⇒ Object
bub take cannoli for 20 minutes deploy master.
Instance Method Summary collapse
Methods inherited from BubBot::Slack::Command
Constructor Details
This class inherits a constructor from BubBot::Slack::Command
Class Method Details
.aliases ⇒ Object
bub take cannoli for 20 minutes deploy master
11 12 13 |
# File 'lib/bub_bot/slack/commands/claim.rb', line 11 def self.aliases %w(claim take gimmee canhaz) end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bub_bot/slack/commands/claim.rb', line 15 def run server = duration = deploy = nil iterator = create_token_iterator # Skip the command name itself iterator.next while token = iterator.peek if token == 'for' puts 'got for' iterator.next duration = parse_duration(iterator) elsif token.to_i > 0 puts 'got int' duration = parse_duration(iterator) elsif servers.names.include?(token) puts 'got server' server = iterator.next elsif token == 'deploy' puts 'got deploy' raise RespondableError.new('Use the new deploy command to deploy, not the take command.') else raise RespondableError.new("I'm not sure what '#{token}' means.") end end # Default to the first unclaimed server if no server was specified. If there # are no unclaimed servers, error. unless server unless server = servers.first_unclaimed raise RespondableError.new("No available servers.") end end duration ||= DEFAULT_DURATION = { server_name: server, duration: duration, user: source_user_name }.compact result = servers.take() time_ago = time_ago_in_words(result['expires_at']) respond("#{source_user_name} has #{server} for the next #{time_ago}") end |