Class: FixedWidth::Definition
- Inherits:
-
Object
- Object
- FixedWidth::Definition
- Defined in:
- lib/fixed_width/definition.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sections ⇒ Object
readonly
Returns the value of attribute sections.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Definition
constructor
A new instance of Definition.
- #method_missing(method, *args, &block) ⇒ Object
- #section(name, options = {}) {|section| ... } ⇒ Object
- #template(name, options = {}) {|section| ... } ⇒ Object
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(={}) @sections = [] @templates = {} @options = { :align => :right }.merge() 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
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/fixed_width/definition.rb', line 3 def @options end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
3 4 5 |
# File 'lib/fixed_width/definition.rb', line 3 def sections @sections end |
#templates ⇒ Object (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
11 12 13 14 15 16 17 18 19 |
# File 'lib/fixed_width/definition.rb', line 11 def section(name, ={}, &block) raise DuplicateSectionNameError.new("Duplicate section name: '#{name}'") if @sections.detect{|s| s.name == name } section = FixedWidth::Section.new(name, @options.merge()) section.definition = self yield(section) @sections << section section end |
#template(name, options = {}) {|section| ... } ⇒ Object
21 22 23 24 25 |
# File 'lib/fixed_width/definition.rb', line 21 def template(name, ={}, &block) section = FixedWidth::Section.new(name, @options.merge()) yield(section) @templates[name] = section end |