diff --git a/lib/oga/ruby/node.rb b/lib/oga/ruby/node.rb index 5927392..682b686 100644 --- a/lib/oga/ruby/node.rb +++ b/lib/oga/ruby/node.rb @@ -148,6 +148,15 @@ module Oga Node.new(:if, [self, yield]) end + ## + # Wraps the current node in an `if !...` statement. + # + # @see [#if_true] + # + def if_false + self.not.if_true { yield } + end + ## # Wraps the current node in a `while` statement. # diff --git a/spec/oga/ruby/node_spec.rb b/spec/oga/ruby/node_spec.rb index 1e12176..8f29617 100644 --- a/spec/oga/ruby/node_spec.rb +++ b/spec/oga/ruby/node_spec.rb @@ -133,6 +133,21 @@ describe Oga::Ruby::Node do end end + describe '#if_false' do + it 'returns an if statement Node' do + condition = described_class.new(:lit, %w{number}) + body = described_class.new(:lit, %w{10}) + statement = condition.if_false { body } + + statement.type.should == :if + + statement.to_a[0].type.should == :send + + statement.to_a[0].to_a.should == [condition, '!'] + statement.to_a[1].should == body + end + end + describe '#while_true' do it 'returns a while statement Node' do condition = described_class.new(:lit, %w{number})