Skip to content

Commit

Permalink
feat: add Data#[]
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytonyjan committed Sep 12, 2017
1 parent 3ebbc11 commit 9fbf4d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ext/exif/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static const char* attr_readers[] = {"ifds", "aperture_value", "artist", "batter

static VALUE new(VALUE self, VALUE input);
static VALUE dump(VALUE self);
static VALUE brackets(VALUE self, VALUE ifd_symbol);
static void each_content(ExifContent *ec, void *user_data);
static void each_entry(ExifEntry *, void *user_data);
static VALUE exif_entry_to_rb_value(ExifEntry *);
Expand All @@ -29,6 +30,7 @@ void init_data(){
rb_define_alias(rb_cExifData, "to_h", "ifds");
rb_define_singleton_method(rb_cExifData, "new", new, 1);
rb_define_method(rb_cExifData, "dump", dump, 0);
rb_define_method(rb_cExifData, "[]", brackets, 1);
}

VALUE new(VALUE self, VALUE input){
Expand Down Expand Up @@ -66,6 +68,10 @@ static VALUE dump(VALUE self){
return Qnil;
}

static VALUE brackets(VALUE self, VALUE ifd_symbol){
return rb_hash_aref(rb_iv_get(self, "@ifds"), ifd_symbol);
}

static void each_content(ExifContent *ec, void *self_ptr){
VALUE *self;
ExifIfd ifd;
Expand Down
8 changes: 8 additions & 0 deletions test/test_exif.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

class TestExif < Minitest::Test
module Shared
def test_brackets
assert_equal data.ifds[:ifd0], data[:ifd0]
assert_equal data.ifds[:ifd1], data[:ifd1]
assert_equal data.ifds[:exif], data[:exif]
assert_equal data.ifds[:gps], data[:gps]
assert_equal data.ifds[:interoperability], data[:interoperability]
end

def test_to_h
assert_equal data.ifds, data.to_h
end
Expand Down

0 comments on commit 9fbf4d7

Please sign in to comment.