Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.07 KB | None | 0 0
  1. require "pdfkit"
  2.  
  3. def generate_quadratic
  4.     pool = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
  5.  
  6.     return "#{pool.sample}x^2 + #{pool.sample}x + #{pool.sample}"
  7.  
  8. end
  9.  
  10. def generate_cubic
  11.     pool = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
  12.  
  13.     return "#{pool.sample}x^3 + #{pool.sample}x^2 + #{pool.sample}x + #{pool.sample}"
  14. end
  15.  
  16. def make_html_and_pdf equations
  17.     myfile = File.new("equations.html", "w+")
  18.  
  19.     myfile.puts "<html>"
  20.     myfile.puts "<title>Equations</title>"
  21.     myfile.puts "<style>body > div{clear:both;float:left; width:500px;}</style>"
  22.     myfile.puts "<body style=\"padding: 15px;\">"
  23.    
  24.     equations.each_with_index do |e,index|
  25.         myfile.puts "#{e}"
  26.         myfile.puts "<br><br>" 
  27.     end
  28.  
  29.     myfile.puts "</body>"
  30.     myfile.puts "</html>"
  31.  
  32.     kit = PDFKit.new(myfile)
  33.     kit.to_file("equations.pdf")
  34.    
  35. end
  36.  
  37.  
  38.  
  39. print "Enter how many test you want = "
  40.  
  41. user_input = gets.chomp
  42. user_input =  user_input.to_i
  43.  
  44. equations = Array.new
  45.  
  46. user_input.times do
  47.     equations << generate_quadratic
  48.     equations << generate_cubic
  49. end
  50.  
  51. make_html_and_pdf equations
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement