Class: YoutubeParser::Resource

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/youtube_parser/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
10
# File 'lib/youtube_parser/resource.rb', line 5

def initialize(hash = {})
  @hash = hash
  @default_method_value = hash.delete(:default_method_value)

  super(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



20
21
22
23
24
25
# File 'lib/youtube_parser/resource.rb', line 20

def method_missing(method, *args, &block)
  super_method = super
  return super_method if super_method

  @default_method_value
end

Instance Method Details

#attributesObject



12
13
14
# File 'lib/youtube_parser/resource.rb', line 12

def attributes
  @attributes ||= @hash.transform_keys(&:to_sym)
end

#keysObject



16
17
18
# File 'lib/youtube_parser/resource.rb', line 16

def keys
  @keys ||= attributes.keys
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/youtube_parser/resource.rb', line 27

def respond_to_missing?(method_name, include_private = false)
  @hash.keys.include?(method_name) ||
    @hash.keys.map(&:to_s).include?(method_name) || super
end