Class: FixedWidth::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/fixed_width/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Definition

Returns a new instance of Definition.



5
6
7
8
9
# File 'lib/fixed_width/definition.rb', line 5

def initialize(options={})
  @sections  = []
  @templates = {}
  @options   = { :align => :right }.merge(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



27
28
29
# File 'lib/fixed_width/definition.rb', line 27

def method_missing(method, *args, &block)
  section(method, *args, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/fixed_width/definition.rb', line 3

def options
  @options
end

#sectionsObject (readonly)

Returns the value of attribute sections.



3
4
5
# File 'lib/fixed_width/definition.rb', line 3

def sections
  @sections
end

#templatesObject (readonly)

Returns the value of attribute templates.



3
4
5
# File 'lib/fixed_width/definition.rb', line 3

def templates
  @templates
end

Instance Method Details

#section(name, options = {}) {|section| ... } ⇒ Object

Yields:

Raises:



11
12
13
14
15
16
17
18
19
# File 'lib/fixed_width/definition.rb', line 11

def section(name, options={}, &block)
  raise DuplicateSectionNameError.new("Duplicate section name: '#{name}'") if @sections.detect{|s| s.name == name }

  section = FixedWidth::Section.new(name, @options.merge(options))
  section.definition = self
  yield(section)
  @sections << section
  section
end

#template(name, options = {}) {|section| ... } ⇒ Object

Yields:



21
22
23
24
25
# File 'lib/fixed_width/definition.rb', line 21

def template(name, options={}, &block)
  section = FixedWidth::Section.new(name, @options.merge(options))
  yield(section)
  @templates[name] = section
end