Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

Ruby Input Connector Names

For general discussion related FlowStone

Ruby Input Connector Names

Postby DaveyBoy » Fri Jun 30, 2017 2:17 pm

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
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby Input Connector Names

Postby tulamide » Fri Jun 30, 2017 2:48 pm

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")
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby Input Connector Names

Postby DaveyBoy » Fri Jun 30, 2017 4:34 pm

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 :)
Attachments
Input Names.fsm
(456 Bytes) Downloaded 887 times
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby Input Connector Names

Postby tulamide » Fri Jun 30, 2017 6:19 pm

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?
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby Input Connector Names

Postby DaveyBoy » Fri Jun 30, 2017 9:32 pm

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
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby Input Connector Names

Postby DaveyBoy » Fri Jun 30, 2017 10:09 pm

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 :)
Attachments
Input Names - Working.fsm
(1.05 KiB) Downloaded 872 times
User avatar
DaveyBoy
 
Posts: 131
Joined: Wed May 11, 2016 9:18 pm
Location: Leeds UK

Re: Ruby Input Connector Names

Postby tulamide » Sat Jul 01, 2017 2:44 am

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!
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany


Return to General

Who is online

Users browsing this forum: No registered users and 77 guests