Class: SC2Profile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile_url, options = [:name, :race, :points, :league, :portrait_style]) ⇒ SC2Profile


Constructor method




28
29
30
31
32
# File 'lib/sc2profile.rb', line 28

def initialize(profile_url, options=[:name, :race, :points, :league, :portrait_style])
  @url = profile_url
  @options = options
  self.scrape @options
end

Instance Attribute Details

#leagueObject (readonly)


Accessor




18
19
20
# File 'lib/sc2profile.rb', line 18

def league
  @league
end

#nameObject (readonly)


Accessor




18
19
20
# File 'lib/sc2profile.rb', line 18

def name
  @name
end

#optionsObject

Returns the value of attribute options.



19
20
21
# File 'lib/sc2profile.rb', line 19

def options
  @options
end

#pointsObject (readonly)


Accessor




18
19
20
# File 'lib/sc2profile.rb', line 18

def points
  @points
end

#portrait_styleObject (readonly)


Accessor




18
19
20
# File 'lib/sc2profile.rb', line 18

def portrait_style
  @portrait_style
end

#raceObject (readonly)


Accessor




18
19
20
# File 'lib/sc2profile.rb', line 18

def race
  @race
end

#urlObject

Returns the value of attribute url.



19
20
21
# File 'lib/sc2profile.rb', line 19

def url
  @url
end

Instance Method Details

#==(o) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/sc2profile.rb', line 45

def ==(o)
  if o.is_a? SC2Profile
    @url == o.url
  else
    false
  end
end

#scrape(options) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/sc2profile.rb', line 53

def scrape(options)
  @url.chop! if @url.last == '/'
  @url.gsub!(/(.+\/sc2\/)(\w{2})(\/profile\/.+)/, '\1en\3')
  html = Nokogiri::HTML(open("#{@url}/ladder/leagues"))

  options.each do |option|
    instance_variable_set("@#{option.to_s}".to_sym, self.send("scrape_#{option.to_s}", html))
  end
end

#to_sObject


Public methods




41
42
43
# File 'lib/sc2profile.rb', line 41

def to_s
  "#{@name} (#{@league}, #{@race}, #{@points} pts)"
end