Class: Slither::Definition
- Inherits:
-
Object
- Object
- Slither::Definition
- Defined in:
- lib/slither/definition.rb
Overview
A Definition is the parent object that contains the information about how a fixed-width file is formatted. It contains a collection of sections, each of which contains a collection of fields.
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
Initializes a new Definition object.
-
#method_missing(method, *args, &block) ⇒ Section
Provides a way to define sections using method calls.
-
#section(name, options = {}) {|Section| ... } ⇒ Section
Defines a new Section within the Definition.
-
#template(name, options = {}) {|section| ... } ⇒ Object
Defines a template, which can be reused to create multiple sections with the same configuration.
Constructor Details
#initialize(options = {}) ⇒ Definition
Initializes a new Definition object.
15 16 17 18 19 |
# File 'lib/slither/definition.rb', line 15 def initialize( = {}) @sections = [] @templates = {} @options = { align: :right, by_bytes: true }.merge() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Section
Provides a way to define sections using method calls. For example,
you can call `my_section` instead of `section('my_section')`.
79 80 81 |
# File 'lib/slither/definition.rb', line 79 def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing section(method, *args, &block) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/slither/definition.rb', line 7 def @options end |
#sections ⇒ Object (readonly)
Returns the value of attribute sections.
7 8 9 |
# File 'lib/slither/definition.rb', line 7 def sections @sections end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
7 8 9 |
# File 'lib/slither/definition.rb', line 7 def templates @templates end |
Instance Method Details
#section(name, options = {}) {|Section| ... } ⇒ Section
Defines a new Section within the Definition.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slither/definition.rb', line 39 def section(name, = {}, &block) if section_using_reserved_name?(name) || section_already_defined?(name) raise ArgumentError, "Reserved or duplicate section name: '#{name}'" end section = Slither::Section.new(name, @options.merge()) section.definition = self yield(section) if block sections << section section end |
#template(name, options = {}) {|section| ... } ⇒ Object
Defines a template, which can be reused to create multiple sections with the same configuration.
65 66 67 68 69 |
# File 'lib/slither/definition.rb', line 65 def template(name, = {}, &block) section = Slither::Section.new(name, @options.merge()) yield(section) if block @templates[name] = section end |