Class: Banacle::SlashCommand::Parser
- Inherits:
-
Object
- Object
- Banacle::SlashCommand::Parser
- Defined in:
- lib/banacle/slash_command/parser.rb
Defined Under Namespace
Classes: ParseError
Class Method Summary collapse
Instance Method Summary collapse
-
#parse(text) ⇒ Object
/banacle (create|delete) [region] [vpc_id or vpc_name] [cidr_block1,cidr_block2,…].
Class Method Details
.parse(text) ⇒ Object
9 10 11 |
# File 'lib/banacle/slash_command/parser.rb', line 9 def self.parse(text) new.parse(text) end |
Instance Method Details
#parse(text) ⇒ Object
/banacle (create|delete) [region] [vpc_id or vpc_name] [cidr_block1,cidr_block2,…]
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 |
# File 'lib/banacle/slash_command/parser.rb', line 16 def parse(text) elems = text.split(" ") if elems.size > 4 raise ParseError.new("too many arguments") end action, region, vpc_id_or_name, cidr_blocks_str = elems unless action raise ParseError.new("action is required") end unless region raise ParseError.new("region is required") end cidr_blocks = [] if cidr_blocks_str cidr_blocks = cidr_blocks_str.split(",") end SlashCommand::Builder.build( action: action, region: region, vpc_id_or_name: vpc_id_or_name, cidr_blocks: cidr_blocks, ) end |