Class: Exiv2::SubTagAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/exiv2.rb

Instance Method Summary collapse

Constructor Details

#initialize(class_name, sub_tag, parent) ⇒ SubTagAccess

Returns a new instance of SubTagAccess.



31
32
33
34
35
# File 'lib/exiv2.rb', line 31

def initialize(class_name, sub_tag, parent)
  @class_name = class_name.split("::").last
  @sub_tag = sub_tag
  @parent = parent
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/exiv2.rb', line 41

def method_missing(name, *args)
  method_name = name.to_s
  method_name = method_name[0..-2] if method_name.ends_with?("=")
  return super(name, *args) unless methods.include?(method_name)
  if name.to_s.ends_with?("=")
    @parent.send :[]=, "#{@class_name}.#{@sub_tag}.#{method_name}", *args
  else
    @parent.send :[], "#{@class_name}.#{@sub_tag}.#{method_name}", *args
  end
end

Instance Method Details

#methodsObject



37
38
39
# File 'lib/exiv2.rb', line 37

def methods
  @parent.select {|tag| tag.first.starts_with?("#{@class_name}.#{@sub_tag}")}.map {|tag| tag.first.gsub(/^(\w+)\.(\w+)\.(\w+)$/,'\3')}
end