class Mumukit::Directives::Interpolations
Public Class Methods
new(key=nil)
click to toggle source
# File lib/mumukit/directives/interpolations.rb, line 2 def initialize(key=nil) @key = key end
Public Instance Methods
interpolate(code, sections)
click to toggle source
# File lib/mumukit/directives/interpolations.rb, line 14 def interpolate(code, sections) interpolated = [] var = code.captures(comment_regexp) do substitution = sections[$1] if substitution interpolated << $1 substitution else $& end end [var, interpolated.uniq] end
interpolations?(code)
click to toggle source
# File lib/mumukit/directives/interpolations.rb, line 10 def interpolations?(code) (code =~ comment_regexp).present? end
regexp()
click to toggle source
# File lib/mumukit/directives/interpolations.rb, line 6 def regexp /\.\.\.(.+?)\.\.\./ end
transform(sections)
click to toggle source
# File lib/mumukit/directives/interpolations.rb, line 30 def transform(sections) raise 'Missing key. Build the interpolations with a key in order to use this method' unless @key code = sections[@key] if interpolations? code interpolation, interpolated = interpolate code, sections.except(@key) sections.merge(@key => interpolation).except(*interpolated) else sections end end