@Deprecated // NOTE: should go away once no date.rb is using it @JRubyMethod(name = "_valid_weeknum?", meta = true, required = 4, optional = 1, visibility = Visibility.PRIVATE) public static IRubyObject _valid_weeknum_p(ThreadContext context, IRubyObject self, IRubyObject[] args) { final long sg = args.length > 4 ? val2sg(context, args[4]) : GREGORIAN; final int y = args[0].convertToInteger().getIntValue(); final int w = args[1].convertToInteger().getIntValue(); final int d = args[2].convertToInteger().getIntValue(); final int f = args[3].convertToInteger().getIntValue(); final Long jd = DateUtils._valid_weeknum_p(y, w, d, f, sg); return jd == null ? context.nil : RubyFixnum.newFixnum(context.runtime, jd); }
@Deprecated // NOTE: should go away once no date.rb is using it @JRubyMethod(name = "_valid_weeknum?", meta = true, required = 4, optional = 1, visibility = Visibility.PRIVATE) public static IRubyObject _valid_weeknum_p(ThreadContext context, IRubyObject self, IRubyObject[] args) { final long sg = args.length > 4 ? val2sg(context, args[4]) : GREGORIAN; final int y = args[0].convertToInteger().getIntValue(); final int w = args[1].convertToInteger().getIntValue(); final int d = args[2].convertToInteger().getIntValue(); final int f = args[3].convertToInteger().getIntValue(); final Long jd = DateUtils._valid_weeknum_p(y, w, d, f, sg); return jd == null ? context.nil : RubyFixnum.newFixnum(context.runtime, jd); }
static Long validCivilImpl(IRubyObject year, IRubyObject month, IRubyObject day, final long sg) { final int y = year.convertToInteger().getIntValue(); final int m = getMonth(month); final int d = day.convertToInteger().getIntValue(); return DateUtils._valid_civil_p(y, m, d, sg); }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject idx) { final RubyInteger val = (RubyInteger) self.callMethod(context, "[]", idx); int byte_val = val.getIntValue(); if ( byte_val >= 0 ) return val; return RubyFixnum.newFixnum(context.runtime, byte_val + 256); // byte += 256 if byte < 0 } }
static Long validCivilImpl(IRubyObject year, IRubyObject month, IRubyObject day, final long sg) { final int y = year.convertToInteger().getIntValue(); final int m = getMonth(month); final int d = day.convertToInteger().getIntValue(); return DateUtils._valid_civil_p(y, m, d, sg); }
private static Long validOrdinalImpl(IRubyObject year, int day, final long sg) { final int y = year.convertToInteger().getIntValue(); return DateUtils._valid_ordinal_p(y, day, sg); }
@Override public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject idx, IRubyObject val) { int byte_val = ((RubyInteger) val).getIntValue(); if ( byte_val > 127 ) { val = RubyFixnum.newFixnum(context.runtime, byte_val - 256); // value -= 256 if value > 127 } return self.callMethod(context, "[]=", new IRubyObject[] { idx, val }); } }
@JRubyMethod(name = { "first", "ruby_first" }) // #first ext like with array: [1, 2, 3].first(2) == [1, 2] public static IRubyObject first(final ThreadContext context, final IRubyObject self, final IRubyObject count) { final java.util.List list = unwrapIfJavaObject(self); int len = count.convertToInteger().getIntValue(); int size = list.size(); if ( len > size ) len = size; return Java.getInstance(context.runtime, list.subList(0, len)); }
@JRubyMethod(name = { "last", "ruby_last" }) // #last ext like with array: [1, 2, 3].last(2) == [2, 3] public static IRubyObject last(final ThreadContext context, final IRubyObject self, final IRubyObject count) { final java.util.List list = unwrapIfJavaObject(self); int len = count.convertToInteger().getIntValue(); int size = list.size(); int start = size - len; if ( start < 0 ) start = 0; int end = start + len; if ( end > size ) end = size; return Java.getInstance(context.runtime, list.subList(start, end)); }
@JRubyMethod public static IRubyObject end(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol ) { return context.runtime.newFixnum( matcher.end(idx.toString()) ); } final int group = idx.convertToInteger().getIntValue(); return context.runtime.newFixnum(matcher.end(group)); }
@JRubyMethod public static IRubyObject begin(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol ) { return context.runtime.newFixnum( matcher.start(idx.toString()) ); } final int group = idx.convertToInteger().getIntValue(); return context.runtime.newFixnum( matcher.start(group) ); }
@JRubyMethod(name = "[]", required = 1) public static IRubyObject aref(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol || idx instanceof RubyString ) { return context.runtime.newString( matcher.group(idx.toString()) ); } if ( idx instanceof RubyInteger ) { final int group = ((RubyInteger) idx).getIntValue(); return context.runtime.newString( matcher.group(group) ); } return to_a(context, self).aref(idx); // Range }
private static int simpleIntDiff(IRubyObject n) { final int days = n.convertToInteger().getIntValue(); if (n instanceof RubyRational) { if (((RubyRational) n).getDenominator().getLongValue() != 1) { return days + 1; // MRI rulez: 1/2 -> 1 (but 0.5 -> 0) } } return days; }
private static int simpleIntDiff(IRubyObject n) { final int days = n.convertToInteger().getIntValue(); if (n instanceof RubyRational) { if (((RubyRational) n).getDenominator().getLongValue() != 1) { return days + 1; // MRI rulez: 1/2 -> 1 (but 0.5 -> 0) } } return days; }
@JRubyMethod(name = "[]", required = 1) public static IRubyObject aref(final ThreadContext context, final IRubyObject self, final IRubyObject idx) { final java.util.regex.Matcher matcher = unwrapJavaObject(self); if ( idx instanceof RubySymbol || idx instanceof RubyString ) { return context.runtime.newString( matcher.group(idx.toString()) ); } if ( idx instanceof RubyInteger ) { final int group = ((RubyInteger) idx).getIntValue(); return context.runtime.newString( matcher.group(group) ); } return to_a(context, self).aref(idx); // Range }
private Severity mapRubyLogLevel(IRubyObject arg) { final int rubyId = arg.convertToInteger().getIntValue(); for (Severity severity: Severity.values()) { if (severity.getRubyId() == rubyId) { return severity; } } return Severity.UNKNOWN; }
@JRubyMethod(name = "+") public IRubyObject op_plus(ThreadContext context, IRubyObject n) { if (n instanceof RubyFixnum) { int days = n.convertToInteger().getIntValue(); return newInstance(context, dt.plusDays(+days), off, start); } if (n instanceof RubyNumeric) { return op_plus_numeric(context, (RubyNumeric) n); } throw context.runtime.newTypeError("expected numeric"); }
@JRubyMethod(meta = true) public static IRubyObject dedent_string(ThreadContext context, IRubyObject self, IRubyObject _input, IRubyObject _width) { RubyString input = _input.convertToString(); int wid = _width.convertToInteger().getIntValue(); input.modify19(); int col = LexingCommon.dedent_string(input.getByteList(), wid); return context.runtime.newFixnum(col); }
private static RubyDate civilImpl(ThreadContext context, RubyClass klass, IRubyObject year, IRubyObject month, IRubyObject mday, final long sg) { final int y = (sg > 0) ? getYear(year) : year.convertToInteger().getIntValue(); final int m = getMonth(month); final long[] rest = new long[] { 0, 1 }; final int d = (int) RubyDateTime.getDay(context, mday, rest); DateTime dt = civilDate(context, y, m ,d, getChronology(context, sg, 0)); RubyDate date = new RubyDate(context.runtime, klass, dt, 0, sg); if (rest[0] != 0) date.adjustWithDayFraction(context, dt, rest); return date; }
private static RubyDate civilImpl(ThreadContext context, RubyClass klass, IRubyObject year, IRubyObject month, IRubyObject mday, final long sg) { final int y = (sg > 0) ? getYear(year) : year.convertToInteger().getIntValue(); final int m = getMonth(month); final long[] rest = new long[] { 0, 1 }; final int d = (int) RubyDateTime.getDay(context, mday, rest); DateTime dt = civilDate(context, y, m ,d, getChronology(context, sg, 0)); RubyDate date = new RubyDate(context.runtime, klass, dt, 0, sg); if (rest[0] != 0) date.adjustWithDayFraction(context, dt, rest); return date; }