Created
June 22, 2013 10:20
-
-
Save amrnt/5840304 to your computer and use it in GitHub Desktop.
Ruby Ramallah - Day II
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source "https://rubygems.org/" | |
| gem 'sinatra' | |
| gem 'nokogiri' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ENV['RACK_ENV'] ||= 'development' | |
| require 'bundler/setup' | |
| Bundler.require :default, ENV['RACK_ENV'] | |
| require './web_page' | |
| get "/" do | |
| page_title = WebPage.new(params[:url]).title | |
| "The title page for: #{params[:url]} is <b>#{page_title}</b>" | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'open-uri' | |
| class WebPage | |
| def initialize(url) | |
| @page = Nokogiri::HTML(open(url)) | |
| end | |
| def title | |
| @page.title | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First install Bundler by:
Then run
Every time you modify
Gemfilemake sure to runbundleorbundle install