Class: BmIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/leander/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBmIndex

Returns a new instance of BmIndex.



11
12
13
# File 'lib/leander/index.rb', line 11

def initialize
	@index = Index::Index.new(:path => "#{ENV['HOME']}/.leander.idx")
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



9
10
11
# File 'lib/leander/index.rb', line 9

def index
  @index
end

Instance Method Details

#leander_remove(query) ⇒ Object



22
23
24
25
26
27
# File 'lib/leander/index.rb', line 22

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

#search(query) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/leander/index.rb', line 29

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

#store_webpage(wp) ⇒ Object



15
16
17
18
19
20
# File 'lib/leander/index.rb', line 15

def store_webpage(wp)
	@index << {
		:url => wp.url,
		:doc => wp.doc
	}
end