module CukeModeler::Described
@api private
A mix-in module containing methods used by models that represent an element that has a description. Internal helper class.
Attributes
description[RW]
@api
The description of the element
Private Instance Methods
description_output_string()
click to toggle source
# File lib/cuke_modeler/described.rb, line 18 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 31 def no_description_to_output? description.nil? || description.empty? end
populate_description(parsed_model_data)
click to toggle source
# File lib/cuke_modeler/described.rb, line 35 def populate_description(parsed_model_data) @description = trimmed_description(parsed_model_data['description']) end
trim_leading_blank_lines(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 50 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 58 def trim_leading_spaces(description) non_blank_lines = description.grep(/\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 54 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 66 def trim_trailing_spaces(description) description.map!(&:rstrip) end
trimmed_description(description)
click to toggle source
# File lib/cuke_modeler/described.rb, line 39 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