Examples of RubyHash


Examples of org.jruby.RubyHash

  }

  public RubyHash createRubyInputRow(RowMetaInterface rowMeta, Object[] r) throws KettleException {

    // create a hash for the row, they are not reused on purpose, so the scripting user can safely use them to store entire rows between invocations
    RubyHash rubyRow = new RubyHash(data.runtime);

    String[] fieldNames = rowMeta.getFieldNames();
    for (int i = 0; i < fieldNames.length; i++) {

      String field = fieldNames[i];
      // null values don't need no special treatment, they'll become nil
      if (r[i] == null) {
        rubyRow.put(field, null);
      } else {

        ValueMetaInterface vm = rowMeta.getValueMeta(i);

        switch (vm.getType()) {
        case ValueMeta.TYPE_BOOLEAN:
          rubyRow.put(field, vm.getBoolean(r[i]));
          break;
        case ValueMeta.TYPE_INTEGER:
          rubyRow.put(field, vm.getInteger(r[i]));
          break;
        case ValueMeta.TYPE_STRING:
          rubyRow.put(field, vm.getString(r[i]));
          break;
        case ValueMeta.TYPE_NUMBER:
          rubyRow.put(field, vm.getNumber(r[i]));
          break;
        case ValueMeta.TYPE_NONE:
          rubyRow.put(field, r[i]);
          break;
        case ValueMeta.TYPE_SERIALIZABLE:
          if (r[i] instanceof RubyStepMarshalledObject) {
            Object restoredObject = getMarshal().callMethod(data.runtime.getCurrentContext(), "restore", data.runtime.newString(r[i].toString()));
            rubyRow.put(field, restoredObject);
          } else {
            // try to put the object in there as it is.. should create a nice adapter for the java object
            rubyRow.put(field, r[i]);
          }
          break;
        case ValueMeta.TYPE_BINARY:
          // put a ruby array with bytes in there, that is expensive and should probably be avoided
          rubyRow.put(fieldNames[i],
                data.runtime.newArrayNoCopy(JavaUtil.convertJavaArrayToRuby(data.runtime, ArrayUtils.toObject((byte[]) vm.getBinary(r[i]))))
                );

          break;

        case ValueMeta.TYPE_BIGNUMBER:
          IRubyObject bigDecimalObject = getBigDecimal().callMethod(data.runtime.getCurrentContext(), "new", data.runtime.newString((vm.getBigNumber(r[i])).toString()));
          rubyRow.put(field, bigDecimalObject);
          break;

        case ValueMeta.TYPE_DATE:
          rubyRow.put(field, data.runtime.newTime((vm.getDate(r[i])).getTime()));
          break;

        }

      }
View Full Code Here

Examples of org.jruby.RubyHash

        }

        // get the next row
        if (r != null) {

          RubyHash rubyRow = createRubyInputRow(data.inputRowMeta, r);

          // put the row into the container
          data.container.put("$row", rubyRow);

          // run the script, the result is one or more rows
View Full Code Here

Examples of org.jruby.RubyHash

  }

  private void initInfoRowStreams() throws KettleException {

    // put the info steps into ruby scope
    RubyHash infoSteps = new RubyHash(data.runtime);

    int i = 0;
    for (StreamInterface stream : meta.getStepIOMeta().getInfoStreams()) {

      StepStreamReader reader = new StepStreamReader(this, stream.getStepname());

      // if there's direct input connected as well as info streams present, the info streams *must* be prefetched as per 4.0 API
      if (data.hasDirectInput) {
        RubyArray allRows = reader.readAll();
        BufferStreamReader bReader = new BufferStreamReader(this, allRows);
        infoSteps.put(meta.getInfoSteps().get(i).getRoleName(), bReader);
      } else {
        infoSteps.put(meta.getInfoSteps().get(i).getRoleName(), reader);
      }

      i++;
    }

View Full Code Here

Examples of org.jruby.RubyHash

  }

// line 587 "Parser.rl"

            if (parser.createAdditions) {
                RubyHash match_string = parser.match_string;
                if (match_string != null) {
                    final IRubyObject[] memoArray = { result, null };
                    try {
                      match_string.visitAll(new RubyHash.Visitor() {
                          @Override
                          public void visit(IRubyObject pattern, IRubyObject klass) {
                              if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
                                  memoArray[1] = klass;
                                  throw JumpException.SPECIAL_JUMP;
View Full Code Here

Examples of org.jruby.RubyHash

                    "nesting of " + currentNesting + " is too deep");
            }

            // this is guaranteed to be a RubyHash due to the earlier
            // allocator test at OptionsReader#getClass
            RubyHash result =
                (RubyHash)parser.objectClass.newInstance(context,
                    IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);

           
// line 1866 "Parser.java"
  {
  cs = JSON_object_start;
  }

// line 752 "Parser.rl"
           
// line 1873 "Parser.java"
  {
  int _klen;
  int _trans = 0;
  int _acts;
  int _nacts;
  int _keys;
  int _goto_targ = 0;

  _goto: while (true) {
  switch ( _goto_targ ) {
  case 0:
  if ( p == pe ) {
    _goto_targ = 4;
    continue _goto;
  }
  if ( cs == 0 ) {
    _goto_targ = 5;
    continue _goto;
  }
case 1:
  _match: do {
  _keys = _JSON_object_key_offsets[cs];
  _trans = _JSON_object_index_offsets[cs];
  _klen = _JSON_object_single_lengths[cs];
  if ( _klen > 0 ) {
    int _lower = _keys;
    int _mid;
    int _upper = _keys + _klen - 1;
    while (true) {
      if ( _upper < _lower )
        break;

      _mid = _lower + ((_upper-_lower) >> 1);
      if ( data[p] < _JSON_object_trans_keys[_mid] )
        _upper = _mid - 1;
      else if ( data[p] > _JSON_object_trans_keys[_mid] )
        _lower = _mid + 1;
      else {
        _trans += (_mid - _keys);
        break _match;
      }
    }
    _keys += _klen;
    _trans += _klen;
  }

  _klen = _JSON_object_range_lengths[cs];
  if ( _klen > 0 ) {
    int _lower = _keys;
    int _mid;
    int _upper = _keys + (_klen<<1) - 2;
    while (true) {
      if ( _upper < _lower )
        break;

      _mid = _lower + (((_upper-_lower) >> 1) & ~1);
      if ( data[p] < _JSON_object_trans_keys[_mid] )
        _upper = _mid - 2;
      else if ( data[p] > _JSON_object_trans_keys[_mid+1] )
        _lower = _mid + 2;
      else {
        _trans += ((_mid - _keys)>>1);
        break _match;
      }
    }
    _trans += _klen;
  }
  } while (false);

  _trans = _JSON_object_indicies[_trans];
  cs = _JSON_object_trans_targs[_trans];

  if ( _JSON_object_trans_actions[_trans] != 0 ) {
    _acts = _JSON_object_trans_actions[_trans];
    _nacts = (int) _JSON_object_actions[_acts++];
    while ( _nacts-- > 0 )
  {
      switch ( _JSON_object_actions[_acts++] )
      {
  case 0:
// line 689 "Parser.rl"
  {
                ParserResult res = parseValue(p, pe);
                if (res == null) {
                    p--;
                    { p += 1; _goto_targ = 5; if (truecontinue _goto;}
                } else {
                    if (!parser.objectClass.getName().equals("Hash")) {
                        result.callMethod(context, "[]=", new IRubyObject[] { lastName, res.result });
                    } else {
                        result.op_aset(context, lastName, res.result);
                    }
                    {p = (( res.p))-1;}
                }
            }
  break;
  case 1:
// line 704 "Parser.rl"
  {
                ParserResult res = parseString(p, pe);
                if (res == null) {
                    p--;
                    { p += 1; _goto_targ = 5; if (truecontinue _goto;}
                } else {
                    RubyString name = (RubyString)res.result;
                    if (parser.symbolizeNames) {
                        lastName = context.getRuntime().is1_9()
                                       ? name.intern19()
                                       : name.intern();
                    } else {
                        lastName = name;
                    }
                    {p = (( res.p))-1;}
                }
            }
  break;
  case 2:
// line 722 "Parser.rl"
  {
                p--;
                { p += 1; _goto_targ = 5; if (truecontinue _goto;}
            }
  break;
// line 1997 "Parser.java"
      }
    }
  }

case 2:
  if ( cs == 0 ) {
    _goto_targ = 5;
    continue _goto;
  }
  if ( ++p != pe ) {
    _goto_targ = 1;
    continue _goto;
  }
case 4:
case 5:
  }
  break; }
  }

// line 753 "Parser.rl"

            if (cs < JSON_object_first_final) {
                return null;
            }

            IRubyObject returnedResult = result;

            // attempt to de-serialize object
            if (parser.createAdditions) {
                IRubyObject vKlassName = result.op_aref(context, parser.createId);
                if (!vKlassName.isNil()) {
                    // might throw ArgumentError, we let it propagate
                    IRubyObject klass = parser.info.jsonModule.get().
                            callMethod(context, "deep_const_get", vKlassName);
                    if (klass.respondsTo("json_creatable?") &&
View Full Code Here

Examples of org.jruby.RubyHash

                                   + defaultValue);
    }

    public RubyHash getHash(String key) {
        IRubyObject value = get(key);
        if (value == null || value.isNil()) return new RubyHash(runtime);
        return (RubyHash) value;
    }
View Full Code Here

Examples of org.jruby.RubyHash

      }
    };

    this.settings.on_message_begin = new HTTPCallback() {
      public int cb (http_parser.lolevel.HTTPParser p) {
        headers = new RubyHash(runtime);

        requestUrl = runtime.newString("");
        requestPath = runtime.newString("");
        queryString = runtime.newString("");
        fragment = runtime.newString("");
View Full Code Here

Examples of org.jruby.RubyHash

                    H_ELE(x.cComment);
                    scanner.hpricotAdd(S.focus, ele);
                } else if(sym == x.sym_doctype) {
                    H_ELE(x.cDocType);
                    if(S.strict) {
                        RubyHash h = (RubyHash)attr;
                        h.fastASet(runtime.newSymbol("system_id"), runtime.newString("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"));
                        h.fastASet(runtime.newSymbol("public_id"), runtime.newString("-//W3C//DTD XHTML 1.0 Strict//EN"));
                    }
                    scanner.hpricotAdd(S.focus, ele);
                } else if(sym == x.sym_procins) {
                    IRubyObject match = tag.callMethod(scanner.ctx, "match", x.reProcInsParse);
                    tag = RubyRegexp.nth_match(1, match);
View Full Code Here

Examples of org.jruby.RubyHash

     * @return
     */
    @JRubyMethod
    public RubyHash to_h(ThreadContext context) {
        Ruby runtime = context.getRuntime();
        RubyHash result = RubyHash.newHash(runtime);

        result.op_aset(context, runtime.newSymbol("indent"), indent_get(context));
        result.op_aset(context, runtime.newSymbol("space"), space_get(context));
        result.op_aset(context, runtime.newSymbol("space_before"), space_before_get(context));
        result.op_aset(context, runtime.newSymbol("object_nl"), object_nl_get(context));
        result.op_aset(context, runtime.newSymbol("array_nl"), array_nl_get(context));
        result.op_aset(context, runtime.newSymbol("allow_nan"), allow_nan_p(context));
        result.op_aset(context, runtime.newSymbol("ascii_only"), ascii_only_p(context));
        result.op_aset(context, runtime.newSymbol("quirks_mode"), quirks_mode_p(context));
        result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context));
        result.op_aset(context, runtime.newSymbol("depth"), depth_get(context));
        result.op_aset(context, runtime.newSymbol("buffer_initial_length"), buffer_initial_length_get(context));
        return result;
    }
View Full Code Here

Examples of org.jruby.RubyHash

  }

// line 623 "Parser.rl"

            if (parser.createAdditions) {
                RubyHash match_string = parser.match_string;
                if (match_string != null) {
                    final IRubyObject[] memoArray = { result, null };
                    try {
                      match_string.visitAll(new RubyHash.Visitor() {
                          @Override
                          public void visit(IRubyObject pattern, IRubyObject klass) {
                              if (pattern.callMethod(context, "===", memoArray[0]).isTrue()) {
                                  memoArray[1] = klass;
                                  throw JumpException.SPECIAL_JUMP;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.