From: hiroshi h. <cos...@gm...> - 2014-11-16 06:37:58
|
Hi, > + assert_equal("1.0 GiB", > > + GLib.format_size(1024 * 1024 * 1024, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > Please use GLib.format_size(1024 * 1024 * 1024, :flags => :iec_units) > style API. > > If glib_format_size family adds more options, we also need > to add more arguments with the current style. If we use > options Hash style, we can extend API easily. > Thank you for your suggestion! I've committed `GLib.format_size(1024 * 1024 * 1024, :flags => :iec_units)` style API change at master. > In <2f5...@je...> > "[ruby-gnome2-cvs] ruby-gnome2/ruby-gnome2@2f5d769 [master] glib2: > support flag argument in GLib.format_size" on Sun, 16 Nov 2014 02:48:08 > +0900, > Hiroshi Hatake <nu...@co...> wrote: > > > Hiroshi Hatake 2014-11-16 02:48:08 +0900 (Sun, 16 Nov 2014) > > > > New Revision: 2f5d76909f4cf3db0926d21f410008453769fb00 > > > https://github.com/ruby-gnome2/ruby-gnome2/commit/2f5d76909f4cf3db0926d21f410008453769fb00 > > > > Message: > > glib2: support flag argument in GLib.format_size > > > > Modified files: > > glib2/ext/glib2/rbglib_fileutils.c > > glib2/ext/glib2/rbglib_utils.c > > glib2/test/test_file_utils.rb > > > > Modified: glib2/ext/glib2/rbglib_fileutils.c (+10 -3) > > =================================================================== > > --- glib2/ext/glib2/rbglib_fileutils.c 2014-11-16 02:49:55 +0900 > (66eacf4) > > +++ glib2/ext/glib2/rbglib_fileutils.c 2014-11-16 02:48:08 +0900 > (ee4f22b) > > @@ -59,9 +59,16 @@ rbglib_m_format_size_for_display(G_GNUC_UNUSED VALUE > self, VALUE size) > > > > #if GLIB_CHECK_VERSION(2, 30, 0) > > static VALUE > > -rbglib_m_format_size(G_GNUC_UNUSED VALUE self, VALUE size) > > +rbglib_m_format_size(int argc, VALUE *argv, VALUE self) > > { > > - return CSTR2RVAL_FREE(g_format_size(NUM2UINT(size))); > > + VALUE rb_size, rb_flag; > > + > > + rb_scan_args(argc, argv, "11", &rb_size, &rb_flag); > > + if (NIL_P(rb_flag)) > > + return CSTR2RVAL_FREE(g_format_size(NUM2UINT(rb_size))); > > + else > > + return CSTR2RVAL_FREE(g_format_size_full(NUM2UINT(rb_size), > > + NUM2INT(rb_flag))); > > } > > #endif > > > > @@ -101,6 +108,6 @@ Init_glib_fileutils(void) > > #endif > > #if GLIB_CHECK_VERSION(2, 30, 0) > > rbg_define_singleton_method(mGLib, "format_size", > > - rbglib_m_format_size, 1); > > + rbglib_m_format_size, -1); > > #endif > > } > > > > Modified: glib2/ext/glib2/rbglib_utils.c (+5 -0) > > =================================================================== > > --- glib2/ext/glib2/rbglib_utils.c 2014-11-16 02:49:55 +0900 (6ad0e1e) > > +++ glib2/ext/glib2/rbglib_utils.c 2014-11-16 02:48:08 +0900 (484ba2c) > > @@ -293,6 +293,11 @@ Init_glib_utils(void) > > G_DEF_CONSTANTS(RG_TARGET_NAMESPACE, G_TYPE_USER_DIRECTORY, "G_"); > > #endif > > > > +#if GLIB_CHECK_VERSION(2, 30, 0) > > + G_DEF_CLASS(G_TYPE_FORMAT_SIZE_FLAGS, > > + "FormatSizeFlags", RG_TARGET_NAMESPACE); > > +#endif > > + > > RG_DEF_SMETHOD(application_name, 0); > > RG_DEF_SMETHOD(set_application_name, 1); > > RG_DEF_SMETHOD(prgname, 0); > > > > Modified: glib2/test/test_file_utils.rb (+21 -0) > > =================================================================== > > --- glib2/test/test_file_utils.rb 2014-11-16 02:49:55 +0900 (2a402be) > > +++ glib2/test/test_file_utils.rb 2014-11-16 02:48:08 +0900 (232dfc8) > > @@ -22,4 +22,25 @@ class TestGLibFileUtils < Test::Unit::TestCase > > assert_equal("1.5 MB", GLib.format_size(1000 * 1000 * 1.5)) > > assert_equal("1.0 GB", GLib.format_size(1000 * 1000 * 1000)) > > end > > + > > + def test_format_size_with_IEC_UNITS > > + only_glib_version(2, 30, 0) > > + > > + assert_equal("1.0 KiB", > > + GLib.format_size(1024, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > + > > + assert_equal("10.0 KiB", > > + GLib.format_size(1024 * 10, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > + assert_equal("1.0 MiB", > > + GLib.format_size(1024 * 1024, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > + assert_equal("1.5 MiB", > > + GLib.format_size(1024 * 1024 * 1.5, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > + assert_equal("1.0 GiB", > > + GLib.format_size(1024 * 1024 * 1024, > > + GLib::FormatSizeFlags::IEC_UNITS)) > > + end > > end > > > ------------------------------------------------------------------------------ > Comprehensive Server Monitoring with Site24x7. > Monitor 10 servers for $9/Month. > Get alerted through email, SMS, voice calls or mobile push notifications. > Take corrective actions from your mobile device. > > http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |