Class: OracleDB::IntervalYM

Inherits:
Object
  • Object
show all
Defined in:
lib/oracledb.rb,
ext/oracledb/rboradb_datetime.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



223
224
225
226
227
228
229
230
231
232
# File 'ext/oracledb/rboradb_datetime.c', line 223

static VALUE interval_ym_initialize(int argc, VALUE *argv, VALUE self)
{
    dpiIntervalYM *val = To_IntervalYM(self);
    VALUE years, months;

    rb_scan_args(argc, argv, "02", &years, &months);
    val->years = NIL_P(years) ? 0 : NUM2INT(years);
    val->months = NIL_P(months) ? 0 : NUM2INT(months);
    return Qnil;
}

Instance Method Details

#inspectObject



187
188
189
190
191
# File 'lib/oracledb.rb', line 187

def inspect
  "#<#{self.class}:#{self.to_s}>"
rescue
  "#<#{self.class}:ERROR: #{$!.message}>"
end

#monthsObject



256
257
258
259
260
# File 'ext/oracledb/rboradb_datetime.c', line 256

static VALUE interval_ym_months(VALUE self)
{
    dpiIntervalYM *val = To_IntervalYM(self);
    return INT2NUM(val->months);
}

#to_aObject



234
235
236
237
238
239
240
241
# File 'ext/oracledb/rboradb_datetime.c', line 234

static VALUE interval_ym_to_a(VALUE self)
{
    dpiIntervalYM *val = To_IntervalYM(self);
    VALUE ary = rb_ary_new_capa(2);
    rb_ary_push(ary, INT2NUM(val->years));
    rb_ary_push(ary, INT2NUM(val->months));
    return ary;
}

#to_sObject



243
244
245
246
247
248
# File 'ext/oracledb/rboradb_datetime.c', line 243

static VALUE interval_ym_to_s(VALUE self)
{
    dpiIntervalYM *val = To_IntervalYM(self);
    char sign = (val->years >= 0 && val->months >= 0) ? '+' : '-';
    return rb_sprintf("%c%9d-%02d", sign, abs(val->years), abs(val->months));
}

#yearsObject



250
251
252
253
254
# File 'ext/oracledb/rboradb_datetime.c', line 250

static VALUE interval_ym_years(VALUE self)
{
    dpiIntervalYM *val = To_IntervalYM(self);
    return INT2NUM(val->years);
}