module RuWEB::Save

Saves the content

Public Instance Methods

init(file, content) click to toggle source
# File lib/ruweb/save.rb, line 8
def init(file, content)
  content = File.extname(file) == '.md' ? content : convert_data_of(content)
  puts "🕷️ ruweb: parameter detected: saving '#{file}' in '#{Dir.pwd}'"
  File.write(file, content)
end

Private Instance Methods

convert_data_of(content) click to toggle source
# File lib/ruweb/save.rb, line 16
def convert_data_of(content)
  content.map { |e| "$ #{e[:cmd]}\n#{numerate(e[:data])}" }.join("\n\n")
end
format(num, total_num) click to toggle source
# File lib/ruweb/save.rb, line 26
def format(num, total_num)
  num  += 1
  chars = total_num.to_s.length - num.to_s.length
  space = ' ' * chars
  "#{space}#{num}"
end
numerate(data) click to toggle source
# File lib/ruweb/save.rb, line 20
def numerate(data)
  data = data.split("\n")
  data.map!.with_index { |e, i| "#{format(i, data.length)}│ #{e}" }
  data.join("\n")
end