Class: MarkyMarkdown::Transformer

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

Class Method Summary collapse

Class Method Details

.compile(input) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



10
11
12
13
14
15
16
17
18
# 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) ⇒ Object



5
6
7
8
# 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