class Rezept::Converter
Public Instance Methods
dslfile_to_h(dsl_file)
click to toggle source
# File lib/rezept/converter.rb, line 61 def dslfile_to_h(dsl_file) context = DSLContext.new context.eval_dsl(dsl_file) end
filename(name)
click to toggle source
# File lib/rezept/converter.rb, line 66 def filename(name) name.gsub!(/\W+/, '_') end
set_options(options)
click to toggle source
# File lib/rezept/converter.rb, line 6 def set_options(options) @options = options end
to_dsl(doc)
click to toggle source
# File lib/rezept/converter.rb, line 18 def to_dsl(doc) exclude_key = proc do |k| false end key_conv = proc do |k| k = k.to_s if k !~ /\A[_a-z]\w+\Z/i "_(#{k.inspect})" else k end end name = doc['name'] document_type = doc['document_type'] hash = {} hash['account_ids'] = doc['account_ids'] hash['content'] = doc['content'] if doc['content'].kind_of?(String) if @options['dsl_content'] hash['content'] = { __dsl: JSON.parse(doc['content']) } else hash['content'] = doc['content'].gsub(/\R$/, '') end end dsl = Dslh.deval( hash, exclude_key: exclude_key, use_heredoc_for_multi_line: true, key_conv: key_conv, initial_depth: 1 ) <<-EOS #{document_type} #{name.inspect} do #{dsl} end EOS end
to_dsl_all(docs)
click to toggle source
# File lib/rezept/converter.rb, line 10 def to_dsl_all(docs) dsls = [] docs.each do |doc| dsls << to_dsl(doc) end dsls.join("\n") end