Class: Fight

Inherits:
Object show all
Defined in:
lib/fight.rb

Instance Method Summary collapse

Constructor Details

#initializeFight

Returns a new instance of Fight.



5
6
7
8
# File 'lib/fight.rb', line 5

def initialize
  process_options
  fight!
end

Instance Method Details

#contestantsObject



12
13
14
# File 'lib/fight.rb', line 12

def contestants
  ARGV.to_a
end

#fight!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fight.rb', line 15

def fight!
  contestants.collect do |contestant|
    contestant = %{"#{contestant}"} if @quote
    page = open(url_for(contestant)).read
    match = page.match(pattern)
    count = match ? match[1] : '0'
    [count, contestant]
  end.sort_by {|result| result[0].gsub(',', '').to_i}.reverse.each do |result|
    puts result * ' -- '
  end
end

#process_optionsObject



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

def process_options
  @quote = !!ARGV.delete("-q")
end