class MarkyMarkdown::Transformer
Public Class Methods
compile(input)
click to toggle source
# File lib/marky_markdown.rb, line 20 def self.compile(input) input[:variables].each do |k, v| next if v.nil? key = "{{ #{k} }}" occurences = Helpers.count_occurences_for(key, input[:body]) occurences.times do input[:body] [key] = v if input[:body].include? key end end input[:body] end
identify_variables(str)
click to toggle source
# File lib/marky_markdown.rb, line 10 def self.identify_variables(str) shortened = Helpers.shorten_str(str) key_value_array = Helpers.split_str_by_returns(shortened).map do |v| v.split("=") unless v.strip.empty? end.compact Hash[key_value_array.map { |key, value| [key, value] }] end
transform(str)
click to toggle source
# File lib/marky_markdown.rb, line 5 def self.transform(str) variable_hash = self.identify_variables(str) self.compile({variables: variable_hash, body: str}) end