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
ARRAY Search [RUBY] ??
27 posts
• Page 1 of 3 • 1, 2, 3
ARRAY Search [RUBY] ??
Wow, was hoping that I was getting a little more handle with RUBY ... apparently, 'almost' is still only good in horseshoes
Have made 'some' progress ... like parsing down an XML file that contains 'patch presets' for programs I'm working on. With the latest discovery of these files, it now seems possible that I can use this XML file to create all the patch names and PRG numbers I need, instead of manually assembling them
I'm experimenting with some ideas to see what the better course to take in doing this.
I have a 'working' module that dissects the XML file into 2 separate arrays. One is the 'patch name', the other is its' 'patch number' [MIDI].
I need to get this full list [maybe 100 or so], organized into related groups [by name], and maintain a reference to its patch number. These 'groups' will feed a 'pull down menu' selector, allowing the User to select a patch from a specific 'bank'.
I was thinking that a 'Search Array' routine would be helpful in putting these groups together. Which has, thus-ly, led to much brain abuse
I've been going through RUBY sites trying to get a handle on this ... only to ALMOST get it working .... or completely NOT working with errors messages that I think RUBY is starting to make up it's ridiculous I tell ya
I thought that a 'Search' routine that would find ANY character in the array list would output the full name it was contained in [along with its index number]. As more characters are added, the output list would narrow down to the prime candidates. But man, I've not gotten anything working [Ruby wise]. I did find a 'Green' module that kinda works, but it is not finding/matching with only part of a string .... it basically needs the full name ... and it is CASE sensitive, which adds to the problem.
I think I can do this with a single dimension array ... as the dual attempt really got nowhere [for my attempts].
Any bones that could be tossed this way to help would be most appreciated ! I'm going to try and reduce my 'Xperiment Schematic' to something manageable and readable ... but right now it's a conglomerate of all type of trials ... not pretty
off we go ....
Have made 'some' progress ... like parsing down an XML file that contains 'patch presets' for programs I'm working on. With the latest discovery of these files, it now seems possible that I can use this XML file to create all the patch names and PRG numbers I need, instead of manually assembling them
I'm experimenting with some ideas to see what the better course to take in doing this.
I have a 'working' module that dissects the XML file into 2 separate arrays. One is the 'patch name', the other is its' 'patch number' [MIDI].
I need to get this full list [maybe 100 or so], organized into related groups [by name], and maintain a reference to its patch number. These 'groups' will feed a 'pull down menu' selector, allowing the User to select a patch from a specific 'bank'.
I was thinking that a 'Search Array' routine would be helpful in putting these groups together. Which has, thus-ly, led to much brain abuse
I've been going through RUBY sites trying to get a handle on this ... only to ALMOST get it working .... or completely NOT working with errors messages that I think RUBY is starting to make up it's ridiculous I tell ya
I thought that a 'Search' routine that would find ANY character in the array list would output the full name it was contained in [along with its index number]. As more characters are added, the output list would narrow down to the prime candidates. But man, I've not gotten anything working [Ruby wise]. I did find a 'Green' module that kinda works, but it is not finding/matching with only part of a string .... it basically needs the full name ... and it is CASE sensitive, which adds to the problem.
I think I can do this with a single dimension array ... as the dual attempt really got nowhere [for my attempts].
Any bones that could be tossed this way to help would be most appreciated ! I'm going to try and reduce my 'Xperiment Schematic' to something manageable and readable ... but right now it's a conglomerate of all type of trials ... not pretty
off we go ....
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: ARRAY Search [RUBY] ??
maybe something like this?
- Attachments
-
- search words.fsm
- (391 Bytes) Downloaded 1004 times
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: ARRAY Search [RUBY] ??
RJHollins wrote:
I need to get this full list [maybe 100 or so], organized into related groups [by name], and maintain a reference to its patch number. These 'groups' will feed a 'pull down menu' selector, allowing the User to select a patch from a specific 'bank'.
hmm maybe hashtables would be of interest for that,
http://julioterra.com/journal/2011/10/l ... sh-tables/
http://ruby.about.com/od/rubyfeatures/a/hashes.htm
but i`m not very familiar with hashtables,
-
Nubeat7 - Posts: 1347
- Joined: Sat Apr 14, 2012 9:59 am
- Location: Vienna
Re: ARRAY Search [RUBY] ??
Nubeat7 wrote:maybe something like this?
I mean .... that one line does what about a dozen Prims take
I was trying things like RUBY's find_all, or grep commands. [and probably several others I think]
I also see my additional confusion .... what the difference between @in and @ins is ???
Anyway, this core search works Nubeat .... Thank-you!
I'm still will need to figure out outputting the related INDEX number to the found string.
Also, I will need to make it NOT 'case sensitive' on the search.
Oh ... a question ... in the code ' |s| s.include? ' ... what does the variable 's' represent ??
Thanks again Nubeat ... I have so much very basics still to understand.
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: ARRAY Search [RUBY] ??
I've tried to tap into NuBeat's code to also include an INDEX number of all found strings in the Array ... but no success
The only way I could do this is:
However, this version only finds an exact match. It is also case sensitive. During the enter of search string I see error message in the Ruby interpreter.
I just can't figure out how to include an 'Index' of all strings found [as a separate OUTPUT], as in NuBeat's example.
Then to make it NOT case sensitive.
Still pouring through more Ruby instruction sites, but could really use more help.
Thanks everyone !!
The only way I could do this is:
- Code: Select all
array = @in
array.index @search
output 0, array[(array.index @search)]
output 1, (array.index @search)
However, this version only finds an exact match. It is also case sensitive. During the enter of search string I see error message in the Ruby interpreter.
I just can't figure out how to include an 'Index' of all strings found [as a separate OUTPUT], as in NuBeat's example.
Then to make it NOT case sensitive.
Still pouring through more Ruby instruction sites, but could really use more help.
Thanks everyone !!
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: ARRAY Search [RUBY] ??
Don't know what exactly you are trying to do but this will search array and return index of ellement you search
so output will be: 1
- Code: Select all
a = ["test1","test2","test3","test4"]
a.index{|s| s.include?("test2")}
so output will be: 1
-
TrojakEW - Posts: 111
- Joined: Sat Dec 25, 2010 10:12 am
- Location: Slovakia
Re: ARRAY Search [RUBY] ??
TrojakEW wrote:Don't know what exactly you are trying to do but this will search array and return index of ellement you search
- Code: Select all
a = ["test1","test2","test3","test4"]
a.index{|s| s.include?("test2")}
so output will be: 1
Don't know what exactly you are trying to do
I ask myself that often
What I'm trying to get ...
I have 2 Inputs ... an ARRAY with a list of patch names. The 2nd input is the 'Search' string.
For the Output, I need a list of all Patch names that contain the search string. Exactly as NuBeat's code does.
I also need a separate Array Output of all the Index numbers to the found list.
To this end, I've been trying several Ruby commands ... even looking into 'Hash' ... but have not been able to get this to work.
With NuBeats search code:
- Code: Select all
output @in.select {|s| s.include? @search}
I get the desired output array. But I also need a separate 'INDEX' output of those found.
Getting rid of the 'case sensitive' search I'll try to solve afterward.
As I'm trying to learn, I realize that RUBY is a powerful language. It can sometimes be condensed to very tight coding. Unfortunately, for the amateur, this can make it more difficult to understand or modify. Of course, it is on me to get more experience and understanding. In that pursuit, I sincerely appreciate the knowledge that is shared across the forum.
Thanks !!
- RJHollins
- Posts: 1571
- Joined: Thu Mar 08, 2012 7:58 pm
Re: ARRAY Search [RUBY] ??
Keys to solving this, I think, are...
- Get all the information into a single data structure
- Test strings using regular expressions - they take some learning, but are super versatile.
Something like this...
- Get all the information into a single data structure
- Test strings using regular expressions - they take some learning, but are super versatile.
Something like this...
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
Don't stagnate, mutate to create!
-
trogluddite - Posts: 1730
- Joined: Fri Oct 22, 2010 12:46 am
- Location: Yorkshire, UK
Re: ARRAY Search [RUBY] ??
Welcome back Trog!
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Feel free to donate. Thank you for your contribution.
- tester
- Posts: 1786
- Joined: Wed Jan 18, 2012 10:52 pm
- Location: Poland, internet
Re: ARRAY Search [RUBY] ??
or something like this. it will search for string and return array with index and element from input array
- Code: Select all
a = ["preset_test1","test2","preset_test3","test4"]
names = a.select {|x| x =~ /preset/ }
number = a.each_with_index.select { |i, idx| i =~ /preset/}
number.map! { |i| i[1] }
number.zip(names)
-
TrojakEW - Posts: 111
- Joined: Sat Dec 25, 2010 10:12 am
- Location: Slovakia
27 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: No registered users and 78 guests