0

I would like to have an input-field on my webpage, which allows users to interact with models and perform specific searches within specified models. The system should support various actions, primarily add (+), delete (!) and search (?).

  • To add a new Todoitem to a todolist, the syntax would be like this: +todoitem Some text here #todolistname
  • To delete a post, the syntax would be like this: !post nameofpost
  • To search for a post, the syntax would be: ?post nameofpost

The previous examples adds and removes items from the current signed in user. I would also like the command line to support groups (identified by .groupname)

  1. A valid syntax to add a todoitem to todolist with name important ingroup school would be: +todoitem Some todo text #important.school
  2. Searching for all posts in a group would be: ?post .group
  3. Spaces and order should not matter, except for actual content to be added to model (like the todo text of a todo item). That means +todoitem.school#important Some todo text should give the same result as the input in #1.

Could anyone help me with a way of implementing this effectively in rails? That is how you could effectively search the input-string, decide what the user is trying to do (based on the prefix identificators), and then parsing the input into actual queries ?

Edit: To clarify the last paragraph, as I might have misused the word 'parsing', I was thinking of going through the input-string letter by letter, and then branching/dividing the information so that it can be easily used by pre-defined functions (which perform the queries).

Simrayz
  • 23
  • 5
  • Good luck with that! Seems like you're going to have to create a whole proprietary DSL **and** train you users on how to use the DSL. Sounds like a whole world of hurt. – jvillian Mar 15 '16 at 00:52
  • @jvillian Thanks. The language syntax is already mostly worked out, and the target audience for the web app are students (primarily in the computer sciences), who, if I'm not being too optimistic, should be able to get the hang of it. The command line would of course be an alternative to using the traditional approach with forms and buttons :) – Simrayz Mar 15 '16 at 01:00
  • So, I see that you're OP was actually well stated. But, "how can I effectively implement a free-text parser that resolves to valid ActiveRecord queries?" seems like too big of a question. But, I'm sure some genius here will prove me wrong. – jvillian Mar 15 '16 at 01:07
  • I don't want to write an entire implementation for you, but I think the key tip I can give it to use `active_support/all` methods like `constantize` and `camelcase` - for example, this is how you would link "todo_item" to the actual TodoItem class – max pleaner Mar 15 '16 at 02:09

0 Answers0