class TextOpener::InterceptingMessages

Public Instance Methods

create(params) click to toggle source
# File lib/text_opener.rb, line 16
    def create(params)
      tmp_dir = Dir.mktmpdir
      file_path = File.join(tmp_dir, "#{SecureRandom.uuid}.html")
      File.open(file_path, "w") do |file|
        template = ERB.new(<<-TEMPLATE)
          <html>
            <head><title>SMS to #{params[:to]}</title></head>
            <body>
              <dl>
              <dt>To:</dt><dd>#{params[:to]}</dd>
              <dt>From:</dt><dd>#{params[:from]}</dd>
              </dl>
              <p>#{params[:body]}</p>
            </body>
          </html>
        TEMPLATE
        file.write(template.result(binding))
      end
      Launchy.open(file_path)
    end