Class: HTML5::CLI::PythonicTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/html5/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(format) ⇒ PythonicTemplate

convert Python format string into a Ruby string, ready to eval



230
231
232
233
234
235
# File 'lib/html5/cli.rb', line 230

def initialize format
  @format = format.dup
  @format.gsub!('"', '\\"')
  @format.gsub!(/%\((\w+)\)/, '#{@_\1}')
  @format = '"' + @format + '"'
end

Instance Method Details

#to_s(vars = nil) ⇒ Object

evaluate string



238
239
240
241
# File 'lib/html5/cli.rb', line 238

def to_s(vars=nil)
  vars.each {|var,value| eval "@_#{var}=#{value.dump}"} if vars
  eval @format
end