Class: FixedWidthDSL::FormatString
- Inherits:
-
Object
- Object
- FixedWidthDSL::FormatString
- Defined in:
- lib/fixed_width_dsl.rb
Defined Under Namespace
Classes: Field
Instance Attribute Summary collapse
-
#format_string ⇒ Object
readonly
Returns the value of attribute format_string.
Instance Method Summary collapse
- #apply(attributes) ⇒ Object
- #debug ⇒ Object
-
#initialize ⇒ FormatString
constructor
A new instance of FormatString.
Constructor Details
#initialize ⇒ FormatString
Returns a new instance of FormatString.
7 8 9 10 |
# File 'lib/fixed_width_dsl.rb', line 7 def initialize @fields = [] @format_string = '' end |
Instance Attribute Details
#format_string ⇒ Object (readonly)
Returns the value of attribute format_string.
5 6 7 |
# File 'lib/fixed_width_dsl.rb', line 5 def format_string @format_string end |
Instance Method Details
#apply(attributes) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/fixed_width_dsl.rb', line 30 def apply attributes values = @fields.map do |field| attributes.fetch(field.name) end format(format_string, *values) end |
#debug ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fixed_width_dsl.rb', line 12 def debug output = "field | wi | fro | to | type | flags\n" lines = [] current_column = 1 @fields.each do |field| end_column = current_column + field.width - 1 output.concat format "%-20s | %2i | %3i | %3i | %-7s | %3s\n", field.name, field.width, current_column, end_column, field.type, field.flags current_column += field.width end output end |