Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS Operator for IS BLANK or IS NOT BLANK #18

Open
jheth opened this issue Jul 18, 2014 · 4 comments
Open

IS Operator for IS BLANK or IS NOT BLANK #18

jheth opened this issue Jul 18, 2014 · 4 comments

Comments

@jheth
Copy link

jheth commented Jul 18, 2014

I would like support for an "IS operator where I can do "IS BLANK" or "IS NOT BLANK" to see if a particular value exists or not. In my own expression evaluator I'm using Object#blank? and Object#present? from Rails to check this condition.

Is this something you'd be willing to add or accept a PR for?

@rubysolo
Copy link
Owner

The language is roughly modeled around the Excel formula language, so I would expect it to look more like TRIM(variable) = '' or BLANK(variable) or IS_BLANK(variable). I would consider one of these as a PR.

@jheth
Copy link
Author

jheth commented Jul 19, 2014

Thanks. Good to know. I like the IS_BLANK(variable) syntax. I'll give that a try. I was originally using SQL-like syntax so the expression could be used against a hash or a database.

@jheth
Copy link
Author

jheth commented Jul 24, 2014

This is my test function for testing an empty variable but it doesn't accept nil values. I'm using the :non_group signature to accept any type of variable but it's not accepting nil.

c.add_function(
    name: :blank,
    type: :logical,
    signature: [:non_group],
    body: ->(var) {
      return (var.to_s.strip.empty?)
    }
  )
c.evaluate("BLANK(0)")
 => false 

c.evaluate("BLANK(12345)")
 => false 

c.evaluate("BLANK('   ')")
 => true

c.evaluate("BLANK(nil)")
 => nil 

@rubysolo
Copy link
Owner

nil isn't a keyword inside Dentaku, so you'd probably have to set a variable to nil and pass that in:

c.evaluate("BLANK(foo)", foo: nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants