# If conditions in Ruby code in Logstash

**URL:** <https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274>\
**Category:** Logstash\
**Created:** [December 15, 2015, 7:23pm UTC](https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274 "2015-12-15T19:23:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Omer\_Uludag](https://avatars.discourse-cdn.com/v4/letter/o/b9e5f3/32.png) [@Omer\_Uludag](https://discuss.elastic.co/u/Omer_Uludag)\
**Post date:** [December 15, 2015, 7:23pm UTC](https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274/1 "2015-12-15T19:23:22Z")

</div>

Hello together,

I am new in the Elasticsearch Ecosystem. For that reason, I have unfortunately some problems with the syntax of Ruby in Logstash.  
I have the following snippet code:  
`if [Clat] != '' { ruby { code => " if !event['Clat'].to_s.include? "." event['Clat'].to_f event['Clat'] = event['Clat'] * 360 / (4294967296) event['Clat'] = event['Clat'].round(2) else event['Clat'].to_f event['Clat'] = event['Clat'].round(2) end " } }`  
Other parts of the code are working. The error message is:  
`Error: Expected one of #, {, } at line 42, column 50 (byte 1145) after filter{`  
It points on my first line:  
`if !event['Clat'].to_s.include? "."`

Probably, logstash has problems with the ruby syntax.

Do you maybe know where the problem can lie? I googled for the ruby syntax and created with that the corresponding ruby code.

Best regards

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 15, 2015, 7:28pm UTC](https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274/2 "2015-12-15T19:28:41Z")

</div>

The code block itself is double quoted so you can't have double quotes inside it unless you escape the quotes. I suggest you go with single quotes in all places of your code.

---

<div class="post-metadata">

**Author:** ![Omer\_Uludag](https://avatars.discourse-cdn.com/v4/letter/o/b9e5f3/32.png) [@Omer\_Uludag](https://discuss.elastic.co/u/Omer_Uludag)\
**Post date:** [December 15, 2015, 7:29pm UTC](https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274/3 "2015-12-15T19:29:07Z")

</div>

thank you very much 🙂 nice suggestion 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 5:18am UTC](https://discuss.elastic.co/t/if-conditions-in-ruby-code-in-logstash/37274/4 "2017-07-06T05:18:19Z")

</div>


