Permalink
Browse files

this is better

  • Loading branch information...
1 parent 3d52a7d commit bfe1c4f38635e9b9fa45a29875d9cd8dafe82a38 @nolman committed Sep 17, 2011
Showing with 93 additions and 93 deletions.
  1. +42 −42 lib/leander/index.rb
  2. +38 −38 lib/leander/leander-server.rb
  3. +13 −13 lib/leander/webpage.rb
View
@@ -1,42 +1,42 @@
-require 'ferret'
-require 'highline/import'
-
-require 'leander/webpage.rb'
-
-include Ferret
-
-class BmIndex
- attr_accessor :index
-
- def initialize
- @index = Index::Index.new(:path => "#{ENV['HOME']}/.leander.idx")
- end
-
- def store_webpage(wp)
- @index << {
- :url => wp.url,
- :doc => wp.doc
- }
- end
-
- def leander_remove query
- @index.search_each(query) do |id, score|
- agrees = HighLine.agree("Are you sure you want to delete #{@index[id][:url]} Y/n?") { |q| q.default = 'yes'}
- if agrees then @index.delete(id) end
- end
- end
-
- def search(query)
- output = []
- @index.search_each(query) do |id, score|
- doc = Nokogiri::HTML.parse(@index[id][:doc])
- tmp = {}
- tmp[:url] = index[id][:url]
- tmp[:title] = doc.css('title').inner_text.strip
- tmp[:doc] = doc
- output << tmp
- end
-
- return output
- end
-end
+require 'ferret';
+require 'highline/import';
+
+require 'leander/webpage.rb';
+
+include Ferret;
+
+class BmIndex;
+ attr_accessor :index;
+
+ def initialize;
+ @index = Index::Index.new(:path => "#{ENV['HOME']}/.leander.idx");
+ end;
+
+ def store_webpage(wp);
+ @index << {;
+ :url => wp.url,;
+ :doc => wp.doc;
+ };
+ end;
+
+ def leander_remove query;
+ @index.search_each(query) do |id, score|;
+ agrees = HighLine.agree("Are you sure you want to delete #{@index[id][:url]} Y/n?") { |q| q.default = 'yes'};
+ if agrees then @index.delete(id) end;
+ end;
+ end;
+
+ def search(query);
+ output = [];
+ @index.search_each(query) do |id, score|;
+ doc = Nokogiri::HTML.parse(@index[id][:doc]);
+ tmp = {};
+ tmp[:url] = index[id][:url];
+ tmp[:title] = doc.css('title').inner_text.strip;
+ tmp[:doc] = doc;
+ output << tmp;
+ end;
+
+ return output;
+ end;
+end;
@@ -1,51 +1,51 @@
-#!/usr/bin/ruby
+#!/usr/bin/ruby;
-require 'sinatra/base'
-require 'haml'
-require 'json'
+require 'sinatra/base';
+require 'haml';
+require 'json';
-require 'leander/index.rb'
-require 'leander/webpage.rb'
+require 'leander/index.rb';
+require 'leander/webpage.rb';
-class LeanderServer < Sinatra::Base
+class LeanderServer < Sinatra::Base;
- set :root, File.dirname(__FILE__)
+ set :root, File.dirname(__FILE__);
- helpers do
- def niceify(url, title)
- " <p>#{title}</p><a href=\"#{url}\">#{url}</a>"
- end
- end
+ helpers do;
+ def niceify(url, title);
+ " <p>#{title}</p><a href=\"#{url}\">#{url}</a>";
+ end;
+ end;
- get '/write/*' do
- index = BmIndex.new
- index.store_webpage Webpage.new params[:splat][0]
- end
+ get '/write/*' do;
+ index = BmIndex.new;
+ index.store_webpage Webpage.new params[:splat][0];
+ end;
- get '/search/:query' do
- index = BmIndex.new
- @search_results = index.search params[:query]
- haml :search, :locals => {:result => @search_results }
- end
+ get '/search/:query' do;
+ index = BmIndex.new;
+ @search_results = index.search params[:query];
+ haml :search, :locals => {:result => @search_results };
+ end;
- get '/api/search/:query' do
- content_type :json
- index = BmIndex.new
- @search_results = index.search params[:query].first
- @search_results.map! { |r| {:url => r[:url], :title => r[:title]} }.flatten
+ get '/api/search/:query' do;
+ content_type :json;
+ index = BmIndex.new;
+ @search_results = index.search params[:query].first;
+ @search_results.map! { |r| {:url => r[:url], :title => r[:title]} }.flatten;
- output = {}
- @search_results.each_with_index do |r, n|
- output[n] = {:result => r}
- end
- output.to_json
- end
+ output = {};
+ @search_results.each_with_index do |r, n| ;
+ output[n] = {:result => r};
+ end;
+ output.to_json;
+ end;
- get '/' do
- haml '%div.title Hello world'
- BmIndex.new
- end
+ get '/' do;
+ haml '%div.title Hello world';
+ BmIndex.new;
+ end;
-end
+end;
View
@@ -1,15 +1,15 @@
-require 'rubygems'
-require 'open-uri'
-require 'nokogiri'
+require 'rubygems';
+require 'open-uri';
+require 'nokogiri';
-class Webpage
- attr_reader :url, :doc
- def initialize url
- @url = url
- @doc = Nokogiri::HTML(open(url))
- end
+class Webpage;
+ attr_reader :url, :doc;
+ def initialize url;
+ @url = url;
+ @doc = Nokogiri::HTML(open(url));
+ end;
- def get_title
- return @doc.css('title').content
- end
-end
+ def get_title;
+ return @doc.css('title').content;
+ end;
+end;

0 comments on commit bfe1c4f

Please sign in to comment.