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.



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

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



47
48
49
50
51
52
53
54
55
56
# File 'lib/exiv2.rb', line 47

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



43
44
45
# File 'lib/exiv2.rb', line 43

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