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.
- #prepare_comment_line(line) ⇒ Object
- #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.
134 135 136 137 138 139 140 141 |
# File 'lib/ffi_gen.rb', line 134 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.
132 133 134 |
# File 'lib/ffi_gen.rb', line 132 def output @output end |
Instance Method Details
#comment(&block) ⇒ Object
150 151 152 153 154 |
# File 'lib/ffi_gen.rb', line 150 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
143 144 145 146 147 148 |
# File 'lib/ffi_gen.rb', line 143 def indent(prefix = @indentation_prefix) previous_indentation = @current_indentation @current_indentation += prefix yield @current_indentation = previous_indentation end |
#prepare_comment_line(line) ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/ffi_gen.rb', line 169 def prepare_comment_line(line) line = line.dup line.sub!(/\ ?\*+\/\s*$/, '') line.sub!(/^\s*\/?\*+ ?/, '') line.gsub!(/\\(brief|determine) /, '') line.gsub!('[', '(') line.gsub!(']', ')') line end |
#puts(*lines) ⇒ Object
156 157 158 159 160 |
# File 'lib/ffi_gen.rb', line 156 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
162 163 164 165 166 167 |
# File 'lib/ffi_gen.rb', line 162 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
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/ffi_gen.rb', line 179 def write_description(description, = true, first_line_prefix = "", other_lines_prefix = "") if description.is_a? String description = description.split("\n").map { |line| prepare_comment_line(line) } end 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 |