Class: SC2Profile
- Inherits:
-
Object
- Object
- SC2Profile
- Defined in:
- lib/sc2profile.rb
Instance Attribute Summary collapse
-
#league ⇒ Object
readonly
————————————————————————–.
-
#name ⇒ Object
readonly
————————————————————————–.
-
#options ⇒ Object
Returns the value of attribute options.
-
#points ⇒ Object
readonly
————————————————————————–.
-
#portrait_style ⇒ Object
readonly
————————————————————————–.
-
#race ⇒ Object
readonly
————————————————————————–.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #==(o) ⇒ Object
-
#initialize(profile_url, options = [:name, :race, :points, :league, :portrait_style]) ⇒ SC2Profile
constructor
————————————————————————–.
- #scrape(options) ⇒ Object
-
#to_s ⇒ Object
————————————————————————–.
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, =[:name, :race, :points, :league, :portrait_style]) @url = profile_url = self.scrape end |
Instance Attribute Details
#league ⇒ Object (readonly)
Accessor
18 19 20 |
# File 'lib/sc2profile.rb', line 18 def league @league end |
#name ⇒ Object (readonly)
Accessor
18 19 20 |
# File 'lib/sc2profile.rb', line 18 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/sc2profile.rb', line 19 def end |
#points ⇒ Object (readonly)
Accessor
18 19 20 |
# File 'lib/sc2profile.rb', line 18 def points @points end |
#portrait_style ⇒ Object (readonly)
Accessor
18 19 20 |
# File 'lib/sc2profile.rb', line 18 def portrait_style @portrait_style end |
#race ⇒ Object (readonly)
Accessor
18 19 20 |
# File 'lib/sc2profile.rb', line 18 def race @race end |
#url ⇒ Object
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() @url.chop! if @url.last == '/' @url.gsub!(/(.+\/sc2\/)(\w{2})(\/profile\/.+)/, '\1en\3') html = Nokogiri::HTML(open("#{@url}/ladder/leagues")) .each do |option| instance_variable_set("@#{option.to_s}".to_sym, self.send("scrape_#{option.to_s}", html)) end end |
#to_s ⇒ Object
Public methods
41 42 43 |
# File 'lib/sc2profile.rb', line 41 def to_s "#{@name} (#{@league}, #{@race}, #{@points} pts)" end |