Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Instant RubyMine Assimilation

You're reading from  Instant RubyMine Assimilation

Product type Book
Published in Nov 2013
Publisher Packt
ISBN-13 9781849698764
Pages 66 pages
Edition 1st Edition
Languages
Author (1):
David L. Jones David L. Jones
Profile icon David L. Jones

Managing your implants (Should know)


Now, we will learn how to utilize RubyMine to manage your Gems and external libraries used for your Ruby on Rails programs.

Getting ready

Start RubyMine and open the HelloWorld project that we created earlier. We will be adding an implant to enhance your assimilation process into the collective.

How to do it...

We will now use a Gem in RubyMine by showing the following simple example using the Prawn Gem:

  1. Right-click on the HelloWorld project folder in the left project panel and add a new file to your project. Name it pdf.rb.

  2. Add the following code to this new file:

    require 'prawn'
    Prawn::Document.generate("hello.pdf") do |pdf|
      pdf.font "Courier"
      pdf.stroke_color = "ff0000"
      pdf.line_width = 5
      pdf.stroke do
        pdf.circle([300, 300], 100);
        pdf.circle([350, 320], 20);
        pdf.circle([260, 325], 20);
        pdf.curve [270, 250], [340, 250], :bounds => [[270, 270],[275, 220]]
      end
      pdf.move_down(300)
      pdf.font_size = 36
      pdf.fill_color "000000"
      pdf.draw_text("You will be assimilated!", :at => [40, 40])
    
      pdf.line_width = 1
      pdf.stroke_color = "0000ff"
      pdf.move_to([0, 0])
      grid = 11
      num_lines = 51
      size = (num_lines - 1) * grid
      pdf.stroke do
        51.times do |idx|
          pdf.line([0, idx*grid], [size, idx*grid])
          pdf.line([idx*grid, 0], [idx*grid, size])
        end
      end
    end
  3. Now, right-click on the open source file and select Run pdf. You should get an error similar to in 'require': cannot load such file -- prawn (LoadError). This means that you do not have the required technology to continue the assimilation process. We need to add some Ruby Gems to allow our program to continue.

  4. Open the Settings panel and select the Ruby SDK and Gems panel from the left-hand list. This is where we also changed the version of Ruby that we are using. This panel will allow us to install some specific Ruby Gems that we need.

  5. Hit the button Install Gems... and you will see a screen like the following:

  6. Start typing the name of the Gem you wish to install, which in this case is prawn and the search will begin immediately. Scroll to the right Gem.

  7. Select the Gem in the list at the left-hand side and then hit the button Install. RubyMine will then run the Gem system and install the Gem and all of its appropriate dependencies into your system.

  8. When it is complete, select the prawn gem in the list on the right and you will see the description panel filled with various aspects of the gem for your browsing pleasure.

  9. Once completed, go back and re-run the pdf.rb program.

  10. Since this program actually generates a PDF file, we need to find where it saved the file. In the project window on the left, hit the icon that looks like the following:

    This will synchronize the files inside the folder with the project list. You should now be able to see the file hello.pdf in the project window.

  11. Double-click on this and you will see this file in whichever application you have on your computer that displays PDF files. You should see something like the following:

How it works

The code that we typed in is a simple use of the Prawn Gem. It first requires the Gem code and then starts a block of code that will begin generating the hello.pdf file on the disk. Each command then sets properties of the text, size, colors, circles, and finally draws a grid of lines on the page.

arrow left Previous Chapter
You have been reading a chapter from
Instant RubyMine Assimilation
Published in: Nov 2013 Publisher: Packt ISBN-13: 9781849698764
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}