Ejemplo n.º 1
0
def to_ruby(self, schema):
    term = FirstOp("first", self.term).partial_eval()
    value = term.to_ruby(schema)

    if isinstance(value.frum, CoalesceOp):
        return CoalesceOp(
            "coalesce",
            [StringOp("string", t).partial_eval()
             for t in value.frum.terms]).to_ruby(schema)

    if value.type == BOOLEAN:
        return Ruby(miss=self.term.missing().partial_eval(),
                    type=STRING,
                    expr=value.expr + ' ? "T" : "F"',
                    frum=self)
    elif value.type == INTEGER:
        return Ruby(miss=self.term.missing().partial_eval(),
                    type=STRING,
                    expr="String.valueOf(" + value.expr + ")",
                    frum=self)
    elif value.type == NUMBER:
        return Ruby(miss=self.term.missing().partial_eval(),
                    type=STRING,
                    expr=expand_template(TO_STRING, {"expr": value.expr}),
                    frum=self)
    elif value.type == STRING:
        return value
    else:
        return Ruby(miss=self.term.missing().partial_eval(),
                    type=STRING,
                    expr=expand_template(TO_STRING, {"expr": value.expr}),
                    frum=self)
Ejemplo n.º 2
0
def to_ruby(self, schema):
    term = FirstOp("first", self.term).partial_eval()
    value = term.to_ruby(schema)

    if isinstance(value.frum, CoalesceOp):
        return CoalesceOp("coalesce", [NumberOp("number", t).partial_eval().to_ruby(schema) for t in value.frum.terms]).to_ruby(schema)

    if value.type == BOOLEAN:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr + " ? 1 : 0",
            frum=self
        )
    elif value.type == INTEGER:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == NUMBER:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr=value.expr,
            frum=self
        )
    elif value.type == STRING:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="Double.parseDouble(" + value.expr + ")",
            frum=self
        )
    elif value.type == OBJECT:
        return Ruby(
            miss=term.missing().partial_eval(),
            type=NUMBER,
            expr="((" + value.expr + ") instanceof String) ? Double.parseDouble(" + value.expr + ") : (" + value.expr + ")",
            frum=self
        )