Class: Calendrier::Item

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, options = {}) ⇒ Item

Returns a new instance of Item.



5
6
7
8
# File 'lib/calendrier/item.rb', line 5

def initialize(obj, options = {})
  self.obj = obj
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/calendrier/item.rb', line 10

def method_missing(method, *args, &block)
  ret = nil

  unless obj.nil?
    if options.include?(:field)
      ret = obj.send(options[:field]).send(method)
    elsif !options[method].nil?
      if options[method].is_a?(Symbol)
        ret = obj.send(options[method])
      else
        ret = options[method]
      end
    elsif obj.respond_to?(method)
      ret = obj.send(method)
    end
  end

  ret
end

Instance Attribute Details

#objObject

Returns the value of attribute obj.



3
4
5
# File 'lib/calendrier/item.rb', line 3

def obj
  @obj
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/calendrier/item.rb', line 3

def options
  @options
end

Instance Method Details

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/calendrier/item.rb', line 30

def respond_to?(method, include_private = false)
  ret = true

  begin
    self.send(method)
  rescue NoMethodError
    ret = false
  end

  ret
end