Skip to content

Commit

Permalink
default header prints search args
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGuteMoritz committed May 2, 2009
1 parent e7bf55b commit 2f37de1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/f/finder.rb
Expand Up @@ -44,7 +44,7 @@ def #{name}(v = nil)
end

attr :description, :default_command
attr_reader :commands
attr_reader :commands, :args

def initialize
@commands = { }
Expand Down Expand Up @@ -92,6 +92,8 @@ def find(args = nil, &block)
else
@find.call(http, { :args => args, :terms => args.join(' ') } )
end
ensure
@args = args if args
end

def parse(response = nil, &block)
Expand Down
1 change: 0 additions & 1 deletion lib/f/finder/imdb.rb
Expand Up @@ -4,7 +4,6 @@
find { |http, o| http.get '/find', :q => o[:args].join('+'), :s => 'tt' }

parse do |page, result|
result.header = 'Results for ' + page.at('input[name="q"]')['value']
page.css('td > a[href^="/title/"]').each do |a|
next if a.text.blank?
result << [a.parent.text.squeeze, a['href']]
Expand Down
2 changes: 1 addition & 1 deletion lib/f/prompt.rb
Expand Up @@ -54,7 +54,7 @@ def initialize(finder, results)

def list
puts @finder.description
puts @results.header if @results.header
puts @results.header
puts

@results.each_with_index do |r, i|
Expand Down
4 changes: 4 additions & 0 deletions lib/f/result.rb
Expand Up @@ -45,6 +45,10 @@ def initialize(finder)
super(@items)
end

def header
@header || "Results for #{@finder.args.join(' ')}"
end

def items=(items)
@items.replace(items.map { |a| make_item(a) })
end
Expand Down

0 comments on commit 2f37de1

Please sign in to comment.