Class: ComicVine::CVObject
- Inherits:
-
Object
- Object
- ComicVine::CVObject
- Defined in:
- lib/comic_vine/cv_object.rb
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(args) ⇒ CVObject
constructor
A new instance of CVObject.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
Constructor Details
#initialize(args) ⇒ CVObject
Returns a new instance of CVObject.
3 4 5 6 7 8 9 10 |
# File 'lib/comic_vine/cv_object.rb', line 3 def initialize(args) args.each do |k,v| self.class.class_eval { attr_reader k } v.collect! { |i| CVObject.new i } if v.kind_of?(Array) && !v.empty? && v.first.key?("api_detail_url") v = CVObject.new v if v.kind_of?(Hash) && v.key?("api_detail_url") instance_variable_set "@#{k}", v end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/comic_vine/cv_object.rb', line 16 def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^get_(.*)$/ key = method_sym.to_s.sub "get_", "" if instance_variable_defined?("@#{key}") item = instance_variable_get("@#{key}") if item.kind_of?(Array) && item.first.kind_of?(CVObject) res = [] item.each do |i| res << i.fetch end return res end if item.kind_of?(CVObject) return item.fetch end else super end elsif super end end |
Instance Method Details
#fetch ⇒ Object
12 13 14 |
# File 'lib/comic_vine/cv_object.rb', line 12 def fetch ComicVine::API.get_details_by_url(@api_detail_url) end |