Class: TabBuilder::TabSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tab_builder/tab_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, context, &block) ⇒ TabSet

Returns a new instance of TabSet.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tab_builder/tab_set.rb', line 7

def initialize(options, context, &block)
  @options = options.to_openhash || OpenHash.new
  @context = context
  @tabs = []
  
  # Copy over context instance variables
  @context.instance_variables.each do |iv|
    instance_variable_set(iv, @context.instance_variable_get(iv)) unless instance_variable_defined? iv
  end
  
  instance_eval &block if block_given?        
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



33
34
35
36
37
# File 'lib/tab_builder/tab_set.rb', line 33

def method_missing(name, *args, &block)
  options = args.extract_options!
  tab = Tab.new(name, @options.merge(options), @context, &block)
  self << tab
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/tab_builder/tab_set.rb', line 5

def options
  @options
end

Instance Method Details

#add(tab) ⇒ Object Also known as: <<



24
25
26
# File 'lib/tab_builder/tab_set.rb', line 24

def add(tab)
  @tabs << tab
end

#draw(&block) ⇒ Object



29
30
31
# File 'lib/tab_builder/tab_set.rb', line 29

def draw(&block)
  Drawer.draw(self, @context, &block)
end

#eachObject



20
21
22
# File 'lib/tab_builder/tab_set.rb', line 20

def each
  @tabs.each { |i| yield i }
end