1

ruby code for observe string

Hello, i want to write measure can check and modify objects based on their name content. For examples : if space has "plenum" word in their name so that space's thermalzone would be set as plenum. Have syntax in ruby for observe name string ? Other case, action base on external sources like .csv, .doc, etc Thanks

ngkhanh's avatar
2.2k
ngkhanh
asked 2016-01-22 12:09:08 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2016-01-22 12:13:49 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

2

Calling name.get on any ModelObject (or WorkspaceObject) will return a the object name as a string. With that, you can use the Ruby method include? to check if the name string contains another string, in your case 'Plenum'. So you can write:

if space.name.get.include? "Plenum"
  #do stuff
end

As for external sources, Ruby has a built-in class for parsing .csv files. For word documents you'll have to get a specific gem.

ericringold's avatar
10.6k
ericringold
answered 2016-01-22 12:42:46 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks for your answer. I will try it. I also think about array for temporary content and then .csv. Excel would be properly process .csv with right formatted .csv What is gem ? May i use them with simple editor likes notepad++ or need the whole IDE for ruby. i have never gotten good result with ruby installer - Too much action and setup

ngkhanh's avatar ngkhanh (2016-01-22 13:18:45 -0500) edit
1

Sometimes when doing a compare of strings I've also had to add to_s

if space.name.get.to_s.include? "Plenum"

or

if space.name.get.to_s == "ExactMatch"
David Goldwasser's avatar David Goldwasser (2016-01-22 13:27:42 -0500) edit

Gems are packages that extend the language.

ericringold's avatar ericringold (2016-01-22 13:27:50 -0500) edit
add a comment see more comments