Class: Zelda::Base

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

Overview

Abstract base class to provide common functionality of Zelda importer classes. including method_missing magic to turn an @attributes hash into getters.

Direct Known Subclasses

Aflevering, Omroep, Serie, Zender

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
8
9
10
11
# File 'lib/zelda/base.rb', line 5

def initialize(attributes={})
  @attributes = {}
  
  attributes.each do |key, value|
    @attributes[key.to_sym] = value
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Try both string keys and symbol keys in that order.



16
17
18
19
20
21
22
23
24
# File 'lib/zelda/base.rb', line 16

def method_missing(method, *args, &block)
  if @attributes[method]
    return @attributes[method]
  elsif @attributes.key?(method)
    return nil
  else
    super(method, *args, &block)
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/zelda/base.rb', line 13

def attributes
  @attributes
end