class Safrano::Filter::FuncTree

For functions… should have a single child—> the argument list

For functions… should have a single child—> the argument list note: Adapter specific function helpers like year() or substringof_sig2() need to be mixed in on startup (eg. on publish finalize)

For functions… should have a single child—> the argument list

Public Class Methods

new(val) click to toggle source
Calls superclass method Safrano::Filter::Tree::new
# File lib/odata/filter/tree.rb, line 100
def initialize(val)
  super(val.downcase.to_sym)
end

Public Instance Methods

accept?(tok, typ) click to toggle source

nil is considered as accepted, otherwise non-nil=the error

Calls superclass method Safrano::Filter::RootTree#accept?
# File lib/odata/filter/tree.rb, line 137
def accept?(tok, typ)
  case typ
  when :BinopBool, :BinopArithm
    nil
  else
    super(tok, typ)
  end
end
args() click to toggle source
# File lib/odata/filter/tree.rb, line 104
def args
  @children.first.children
end
arity_full?(cursize) click to toggle source
# File lib/odata/filter/tree.rb, line 108
def arity_full?(cursize)
  cursize >= max_arity
end
check_types() click to toggle source
Calls superclass method Safrano::Filter::RootTree#check_types
# File lib/odata/filter/tree.rb, line 146
def check_types
  case @value
  when :length
    argtyp = args.first.edm_type
    if (argtyp != :any) && (argtyp != :string)
      return Parser::ErrorInvalidArgumentType.new(self,
                                                  expected: :string,
                                                  actual: argtyp)
    end
  end
  super
end
edm_type() click to toggle source
# File lib/odata/filter/tree.rb, line 123
def edm_type
  case @value
  when :concat, :substring
    :string
  when :length
    :int
  when :substringof, :endswith, :startswith
    :bool
  else
    :any
  end
end
leuqes(jh) click to toggle source
# File lib/odata/filter/sequel.rb, line 37
def leuqes(jh)
  case @value
  when :startswith
    Contract.collect_result!(args[0].leuqes(jh),
                             args[1].leuqes_starts_like(jh)) do |l0, l1|
      Sequel.like(l0, l1)
    end

  when :endswith
    Contract.collect_result!(args[0].leuqes(jh),
                             args[1].leuqes_ends_like(jh)) do |l0, l1|
      Sequel.like(l0, l1)
    end

  when :substringof

    # there are multiple possible argument types (but all should return edm.string)
    if args[0].is_a?(QString)
      # substringof('Rhum', name)  -->
      # name contains substr 'Rhum'
      Contract.collect_result!(args[1].leuqes(jh),
                               args[0].leuqes_substringof_sig1(jh)) do |l1, l0|
        Sequel.like(l1, l0)
      end

    # special non standard (ui5 client) case ?
    elsif args[0].is_a?(Literal) && args[1].is_a?(Literal)
      Contract.collect_result!(args[1].leuqes(jh),
                               args[0].leuqes_substringof_sig1(jh)) do |l1, l0|
        Sequel.like(l1, l0)
      end

    elsif args[1].is_a?(QString)
      substringof_sig2(jh) # adapter specific
    else
      # TODO... actually not supported?
      raise Safrano::Filter::Parser::ErrorFunctionArgumentType
    end
  when :concat
    Contract.collect_result!(args[0].leuqes(jh),
                             args[1].leuqes(jh)) do |l0, l1|
      Sequel.join([l0, l1])
    end

  when :length
    args.first.leuqes(jh)
        .map_result! { |l| Sequel.char_length(l) }

  when :trim
    args.first.leuqes(jh)
        .map_result! { |l| Sequel.trim(l) }

  when :toupper
    args.first.leuqes(jh)
        .map_result! { |l| Sequel.function(:upper, l)  }

  when :tolower
    args.first.leuqes(jh)
        .map_result! { |l| Sequel.function(:lower, l)  }

  # all datetime funcs are adapter specific (because sqlite does not have extract)
  when :year
    args.first.leuqes(jh)
        .map_result! { |l| year(l) }

  when :month
    args.first.leuqes(jh)
        .map_result! { |l| month(l) }

  when :second
    args.first.leuqes(jh)
        .map_result! { |l| second(l) }

  when :minute
    args.first.leuqes(jh)
        .map_result! { |l| minute(l) }

  when :hour
    args.first.leuqes(jh)
        .map_result! { |l| hour(l) }

  when :day
    args.first.leuqes(jh)
        .map_result! { |l| day(l) }

  # math functions
  when :round
    args.first.leuqes(jh)
        .map_result! { |l| Sequel.function(:round, l) }

  when :floor
    args.first.leuqes(jh)
        .if_valid { |l| floor(l) }

  when :ceiling
    args.first.leuqes(jh)
        .if_valid { |l| ceiling(l) }
  else
    Safrano::FilterParseError
  end
end
max_arity() click to toggle source
# File lib/odata/filter/tree.rb, line 112
def max_arity
  case @value
  when :replace
    3
  when :concat, :substringof, :substring, :endswith, :startswith
    2
  else
    1
  end
end