EzDevInfo.com

lita

ChatOps for Ruby. Lita: ChatOps for Ruby - Lita.io

Regex capturing from a non capture group in ruby

I am trying to fix a bit of regex I have for a chatops bot for lita. I have the following regex:

/^(?:how\s+do\s+I\s+you\s+get\s+far\s+is\s+it\s+from\s+)?(.+)\s+to\s+(.+)/i

This is supposed to capture the words before and after 'to', with optional words in front that can form questions like: How do I get from x to y, how far from x to y, how far is it from x to y.

expected output:

match 1 : "x"
match 2 : "y"

For the most part my optional words work as expected. But when I pull my response matches, I get the words leading up to the first capture group included.

So, how far is it from sfo to lax should return:

sfo and lax.

But instead returns:

how far is it from sfo and lax


Source: (StackOverflow)

How to add gem dependency to my ruby gem

I think I am fundamentally missing something. I am learning ruby, and have been playing with Lita lately, and wrote(my first) a simple little gem to get some directions/distance from the bot. The problem I am having is where to put a gem dependency in my gem. To work, my gem requires the 'rest-client' gem. Where do I put this in my code so that it is available to my Directions class? Currently, to get it to run, I am requiring the gem in my bots actual gemfile. And when I bundle exec lita, it apparently becomes available for my gem to use... but if I remove it from there, I can't get it to work anywhere in my gem.. what am I missing? It is here if anyone wants to read the code and tell me where I should be adding it:

https://github.com/cashman04/lita-directions

EDIT: I added the dependency like spickermann suggested. Then had to add require 'rest-client'to my directions.rb. Not entirely sure if this is the correct way, but it works now. Thanks for the help spickermann


Source: (StackOverflow)

Advertisements