Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
1

ruby code for observe string

asked 2016-01-22 12:09:08 -0500

ngkhanh's avatar

updated 2016-01-22 12:13:49 -0500

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-01-22 12:42:46 -0500

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.

edit flag offensive delete link more

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2016-01-22 12:09:08 -0500

Seen: 97 times

Last updated: Jan 22 '16