Class: FFIGen::Writer
- Inherits:
-
Object
- Object
- FFIGen::Writer
- Defined in:
- lib/ffi_gen.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #comment(&block) ⇒ Object
- #indent(prefix = @indentation_prefix) ⇒ Object
-
#initialize(indentation_prefix, comment_prefix, comment_start = nil, comment_end = nil) ⇒ Writer
constructor
A new instance of Writer.
- #puts(*lines) ⇒ Object
- #write_array(array, separator = "", first_line_prefix = "", other_lines_prefix = "") ⇒ Object
- #write_description(description, not_documented_message = true, first_line_prefix = "", other_lines_prefix = "") ⇒ Object
Constructor Details
#initialize(indentation_prefix, comment_prefix, comment_start = nil, comment_end = nil) ⇒ Writer
Returns a new instance of Writer.
138 139 140 141 142 143 144 145 |
# File 'lib/ffi_gen.rb', line 138 def initialize(indentation_prefix, comment_prefix, comment_start = nil, comment_end = nil) @indentation_prefix = indentation_prefix @comment_prefix = comment_prefix @comment_start = comment_start @comment_end = comment_end @current_indentation = "" @output = "" end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
136 137 138 |
# File 'lib/ffi_gen.rb', line 136 def output @output end |
Instance Method Details
#comment(&block) ⇒ Object
154 155 156 157 158 |
# File 'lib/ffi_gen.rb', line 154 def comment(&block) self.puts @comment_start unless @comment_start.nil? self.indent @comment_prefix, &block self.puts @comment_end unless @comment_end.nil? end |
#indent(prefix = @indentation_prefix) ⇒ Object
147 148 149 150 151 152 |
# File 'lib/ffi_gen.rb', line 147 def indent(prefix = @indentation_prefix) previous_indentation = @current_indentation @current_indentation += prefix yield @current_indentation = previous_indentation end |
#puts(*lines) ⇒ Object
160 161 162 163 164 |
# File 'lib/ffi_gen.rb', line 160 def puts(*lines) lines.each do |line| @output << "#{@current_indentation}#{line}\n" end end |
#write_array(array, separator = "", first_line_prefix = "", other_lines_prefix = "") ⇒ Object
166 167 168 169 170 171 |
# File 'lib/ffi_gen.rb', line 166 def write_array(array, separator = "", first_line_prefix = "", other_lines_prefix = "") array.each_with_index do |entry, index| entry = yield entry if block_given? puts "#{index == 0 ? first_line_prefix : other_lines_prefix}#{entry}#{index < array.size - 1 ? separator : ''}" end end |
#write_description(description, not_documented_message = true, first_line_prefix = "", other_lines_prefix = "") ⇒ Object
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ffi_gen.rb', line 173 def write_description(description, = true, first_line_prefix = "", other_lines_prefix = "") description.shift while not description.empty? and description.first.strip.empty? description.pop while not description.empty? and description.last.strip.empty? description.map! { |line| line.gsub "\t", " " } space_prefix_length = description.map{ |line| line.index(/\S/) }.compact.min description.map! { |line| line[space_prefix_length..-1] } description << ( ? "(Not documented)" : "") if description.empty? write_array description, "", first_line_prefix, other_lines_prefix end |