Page 1 of 1

Ruby Input Connector Names

Posted: Fri Jun 30, 2017 2:17 pm
by DaveyBoy
Hi Guys

Do any of you Ruby wizards know.. is it possible to parse the names of the input connectors to generate a hash as in the example below, a bit like map.with_index but map.with_names instead?

I hope this is self-explanatory!


Image

Thanks in advance
Dave

Re: Ruby Input Connector Names

Posted: Fri Jun 30, 2017 2:48 pm
by tulamide
Yes, it is. Ruby knows the symbol method to_sym.

"this".to_sym # :this

Be careful not to use it on dynamic data, because there is no garbage collection on such generated symbols! (You would create the famous "memory leak")

Re: Ruby Input Connector Names

Posted: Fri Jun 30, 2017 4:34 pm
by DaveyBoy
Hi Tulamide

Thanks for the swift reply

perhaps I didn't explain very well :oops:

What I actually meant was can we 'extract' the names from the Ruby edit automatically.

In the example if I add another input, hash 'a' is automatically updated with the index but I want to use names for the keys not integers, doesn't matter if they are symbols or strings. Hash 'desired' is just an example of the result I'm after.

Hope this explains it better :)

Re: Ruby Input Connector Names

Posted: Fri Jun 30, 2017 6:19 pm
by tulamide
Haven't downloaded the example yet, but based on your description I'd say it is possible, but more complicated. The only way I am aware of to get the name of the input as a string is via the RubyEditConnector class. This class is provided only in the event method. You'd basically have to trigger each input via

Code: Select all

input index, value

(or externally) and build the Hash one by one using the event method

Code: Select all

def event i, v, t # i = RubyEditConnector, try i.to_s.to_sym or maybe even i.to_sym
end


I hope that helps you more?

Re: Ruby Input Connector Names

Posted: Fri Jun 30, 2017 9:32 pm
by DaveyBoy
Hi Tulamide

I'm not sure I'm understanding you correctly, do you mean like this:

Image

I'm relatively new to Ruby so please be gentle with me :D

Any chance you could post a simple example?

Thanks again

Re: Ruby Input Connector Names

Posted: Fri Jun 30, 2017 10:09 pm
by DaveyBoy
Got it :D

Image

After reading Trogg's excellent API Docs, should have looked there first :oops:

Thanks again anyway Tulamide, you pointed me in the right direction, very helpful as always :)

Re: Ruby Input Connector Names

Posted: Sat Jul 01, 2017 2:44 am
by tulamide
I was about to go out and didn't want to leave you without an answer. So I tried it from my head. And your final result looks exactly as I imagined it. I just forgot about the 'name' method, and I'm sorry for that. Luckily, you were able to help yourself. Well done!