Sha256: 07050c27cd83aedd156b8516c79617c1c877e4af23539a6132f1eb9e30263d95

Contents?: true

Size: 1.88 KB

Versions: 30

Compression:

Stored size: 1.88 KB

Contents

module Polars
  # @private
  class When
    attr_accessor :_when

    def initialize(rbwhen)
      self._when = rbwhen
    end

    def then(statement)
      statement_rbexpr = Utils.parse_into_expression(statement)
      Then.new(_when.then(statement_rbexpr))
    end
  end

  # @private
  class Then < Expr
    attr_accessor :_then

    def initialize(rbthen)
      self._then = rbthen
    end

    def self._from_rbexpr(rbexpr)
      Utils.wrap_expr(rbexpr)
    end

    def _rbexpr
      _then.otherwise(Polars.lit(nil)._rbexpr)
    end

    def when(*predicates, **constraints)
      condition_rbexpr = Utils.parse_predicates_constraints_into_expression(*predicates, **constraints)
      ChainedWhen.new(_then.when(condition_rbexpr))
    end

    def otherwise(statement)
      statement_rbexpr = Utils.parse_into_expression(statement)
      Utils.wrap_expr(_then.otherwise(statement_rbexpr))
    end
  end

  # @private
  class ChainedWhen
    attr_accessor :_chained_when

    def initialize(chained_when)
      self._chained_when = chained_when
    end

    def then(statement)
      statement_rbexpr = Utils.parse_into_expression(statement)
      ChainedThen.new(_chained_when.then(statement_rbexpr))
    end
  end

  # @private
  class ChainedThen < Expr
    attr_accessor :_chained_then

    def initialize(chained_then)
      self._chained_then = chained_then
    end

    def self._from_rbexpr(rbexpr)
      Utils.wrap_expr(rbexpr)
    end

    def _rbexpr
      _chained_then.otherwise(Polars.lit(nil)._rbexpr)
    end

    def when(*predicates, **constraints)
      condition_rbexpr = Utils.parse_predicates_constraints_into_expression(*predicates, **constraints)
      ChainedWhen.new(_chained_then.when(condition_rbexpr))
    end

    def otherwise(statement)
      statement_rbexpr = Utils.parse_into_expression(statement)
      Utils.wrap_expr(_chained_then.otherwise(statement_rbexpr))
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
polars-df-0.15.0-x86_64-linux lib/polars/whenthen.rb
polars-df-0.15.0-x86_64-linux-musl lib/polars/whenthen.rb
polars-df-0.15.0-x86_64-darwin lib/polars/whenthen.rb
polars-df-0.15.0-x64-mingw-ucrt lib/polars/whenthen.rb
polars-df-0.15.0-arm64-darwin lib/polars/whenthen.rb
polars-df-0.15.0-aarch64-linux lib/polars/whenthen.rb
polars-df-0.15.0-aarch64-linux-musl lib/polars/whenthen.rb
polars-df-0.15.0 lib/polars/whenthen.rb
polars-df-0.14.0-x86_64-linux lib/polars/whenthen.rb
polars-df-0.14.0-x86_64-linux-musl lib/polars/whenthen.rb
polars-df-0.14.0-x86_64-darwin lib/polars/whenthen.rb
polars-df-0.14.0-x64-mingw-ucrt lib/polars/whenthen.rb
polars-df-0.14.0-arm64-darwin lib/polars/whenthen.rb
polars-df-0.14.0-aarch64-linux lib/polars/whenthen.rb
polars-df-0.14.0-aarch64-linux-musl lib/polars/whenthen.rb
polars-df-0.14.0 lib/polars/whenthen.rb
polars-df-0.13.0-x86_64-linux lib/polars/whenthen.rb
polars-df-0.13.0-x86_64-linux-musl lib/polars/whenthen.rb
polars-df-0.13.0-x86_64-darwin lib/polars/whenthen.rb
polars-df-0.13.0-x64-mingw-ucrt lib/polars/whenthen.rb