Module: Expando::Expander
- Defined in:
- lib/expando/expander.rb
Constant Summary collapse
- TOKEN_REGEX =
/(?<!\\)\((.*?)\)/
Class Method Summary collapse
-
.expand!(lines) ⇒ Array
Generate a new ‘Expander`.
Class Method Details
.expand!(lines) ⇒ Array
Generate a new ‘Expander`.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/expando/expander.rb', line 24 def ( lines ) = [] lines.each do |line| tokens = line.scan TOKEN_REGEX # Don't perform expansion if no tokens are present. if tokens.empty? << line next end = [] tokens.each_with_index do |token, index| [index] = token[0].split( '|' ) end # Produce Cartesian product of all tokenized values. token_product = [ 0 ].product( *[ 1..-1 ] ) # Generate new expanded lines. token_product.each do |replacement_values| = line replacement_values.each do |value| = .sub( TOKEN_REGEX, value ) end # TODO: Replace multiple spaces with a single space << .strip end end end |