diff options
| author | lstrzebinczyk <[email protected]> | 2017-03-20 21:35:07 +0100 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-03-27 13:45:54 -0400 |
| commit | 79c50dab7f06e4ec288e79e61d0631fdf07b7264 (patch) | |
| tree | 810156ff621084c9bf6268b1f4577ba82fb19b3e | |
| parent | 54b00eb9d3cba566bf80daf6be4c93c1149a7633 (diff) | |
| download | ruby2d-79c50dab7f06e4ec288e79e61d0631fdf07b7264.tar.gz ruby2d-79c50dab7f06e4ec288e79e61d0631fdf07b7264.zip | |
Text#text= will inspect it's input
| -rw-r--r-- | ext/ruby2d/ruby2d.c | 10 | ||||
| -rw-r--r-- | lib/ruby2d/text.rb | 7 | ||||
| -rw-r--r-- | test/text_spec.rb | 18 |
3 files changed, 29 insertions, 6 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 0bc4214..bddc4c6 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -235,14 +235,14 @@ static R_VAL ruby2d_text_init(R_VAL self) { /* - * Ruby2D::Text#text= + * Ruby2D::Text#ext_text_set */ #if MRUBY -static R_VAL ruby2d_text_equals(mrb_state* mrb, R_VAL self) { +static R_VAL ruby2d_ext_text_set(mrb_state* mrb, R_VAL self) { mrb_value text; mrb_get_args(mrb, "o", &text); #else -static R_VAL ruby2d_text_equals(R_VAL self, R_VAL text) { +static R_VAL ruby2d_ext_text_set(R_VAL self, R_VAL text) { r_iv_set(self, "@text", text); #endif @@ -748,8 +748,8 @@ void Init_ruby2d() { // Ruby2D::Text#init r_define_method(ruby2d_text_class, "init", ruby2d_text_init, r_args_none); - // Ruby2D::Text#text= - r_define_method(ruby2d_text_class, "text=", ruby2d_text_equals, r_args_req(1)); + // Ruby2D::Text#ext_text_set + r_define_method(ruby2d_text_class, "ext_text_set", ruby2d_ext_text_set, r_args_req(1)); // Ruby2D::Sound R_CLASS ruby2d_sound_class = r_define_class(ruby2d_module, "Sound"); diff --git a/lib/ruby2d/text.rb b/lib/ruby2d/text.rb index 22325ff..ca27ab8 100644 --- a/lib/ruby2d/text.rb +++ b/lib/ruby2d/text.rb @@ -16,12 +16,17 @@ module Ruby2D @type_id = 5 @x, @y, @size = x, y, size - @text = text + @text = text.to_s @color = Color.new(c) init add end + def text=(msg) + @text = msg.to_s + ext_text_set(@text) + end + def color=(c) @color = Color.new(c) end diff --git a/test/text_spec.rb b/test/text_spec.rb new file mode 100644 index 0000000..22e17a3 --- /dev/null +++ b/test/text_spec.rb @@ -0,0 +1,18 @@ +require 'ruby2d' + +RSpec.describe Ruby2D::Text do + + describe '#text=' do + it 'maps Time to string' do + t = Text.new(0, 0, Time.now, 40, "test/media/bitstream_vera/vera.ttf") + t.text = Time.new(1, 1, 1, 1, 1, 1, 1) + expect(t.text).to eq "0001-01-01 01:01:01 +0000" + end + + it 'maps Number to string' do + t = Text.new(0, 0, 0, 40, "test/media/bitstream_vera/vera.ttf") + t.text = 0 + expect(t.text).to eq "0" + end + end +end |
