module CukeModeler::Described
NOT A PART OF THE PUBLIC API A mix-in module containing methods used by models that represent an element that has a description.
Attributes
description[RW]
The description of the element
Private Instance Methods
description_output_string()
click to toggle source
# File lib/cuke_modeler/described.rb, line 14 def description_output_string text = '' unless description.empty? description_lines = description.split("\n") text << "\n" if description_lines.first =~ /\S/ text << description_lines.join("\n") end text end
no_description_to_output?()
click to toggle source
# File lib/cuke_modeler/described.rb, line 27 def no_description_to_output? description.nil? || description.empty? end
populate_description(model, parsed_model_data)
click to toggle source
# File lib/cuke_modeler/described.rb, line 31 def populate_description(model, parsed_model_data) model.description = trimmed_description(parsed_model_data['description']) end
trim_leading_blank_lines(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 46 def trim_leading_blank_lines(description) description.replace(description.drop_while { |line| line !~ /\S/ }) end
trim_leading_spaces(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 54 def trim_leading_spaces(description) non_blank_lines = description.select { |line| line =~ /\S/ } fewest_spaces = non_blank_lines.collect { |line| line[/^\s*/].length }.min || 0 description.each { |line| line.slice!(0..(fewest_spaces - 1)) } if fewest_spaces.positive? end
trim_trailing_blank_lines(_description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 50 def trim_trailing_blank_lines(_description) # Nothing to do. Already done by the parser but leaving this here in case that changes in future versions. end
trim_trailing_spaces(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 62 def trim_trailing_spaces(description) description.map!(&:rstrip) end
trimmed_description(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 35 def trimmed_description(description) description = description.split("\n") trim_leading_blank_lines(description) trim_trailing_blank_lines(description) trim_leading_spaces(description) trim_trailing_spaces(description) description.join("\n") end