Class: BnetScraper::Starcraft2::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/bnet_scraper/starcraft2/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Profile

Returns a new instance of Profile.



10
11
12
13
14
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 10

def initialize options = {}
  options.each_key do |key|
    self.send "#{key}=", options[key]
  end
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def 
  @account
end

#achievement_pointsObject

Returns the value of attribute achievement_points.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def achievement_points
  @achievement_points
end

#career_gamesObject

Returns the value of attribute career_games.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def career_games
  @career_games
end

#clan_nameObject

Returns the value of attribute clan_name.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def clan_name
  @clan_name
end

#clan_tagObject

Returns the value of attribute clan_tag.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def clan_tag
  @clan_tag
end

#current_solo_leagueObject

Returns the value of attribute current_solo_league.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def current_solo_league
  @current_solo_league
end

#current_team_leagueObject

Returns the value of attribute current_team_league.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def current_team_league
  @current_team_league
end

#games_this_seasonObject

Returns the value of attribute games_this_season.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def games_this_season
  @games_this_season
end

#highest_solo_leagueObject

Returns the value of attribute highest_solo_league.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def highest_solo_league
  @highest_solo_league
end

#highest_team_leagueObject

Returns the value of attribute highest_team_league.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def highest_team_league
  @highest_team_league
end

#leaguesObject

Returns the value of attribute leagues.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def leagues
  @leagues
end

#portraitObject

Returns the value of attribute portrait.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def portrait
  @portrait
end

#protoss_swarm_levelObject

Returns the value of attribute protoss_swarm_level.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def protoss_swarm_level
  @protoss_swarm_level
end

#swarm_levelsObject

Returns the value of attribute swarm_levels.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def swarm_levels
  @swarm_levels
end

#terran_campaign_completionObject

Returns the value of attribute terran_campaign_completion.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def terran_campaign_completion
  @terran_campaign_completion
end

#terran_swarm_levelObject

Returns the value of attribute terran_swarm_level.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def terran_swarm_level
  @terran_swarm_level
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def url
  @url
end

#zerg_campaign_completionObject

Returns the value of attribute zerg_campaign_completion.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def zerg_campaign_completion
  @zerg_campaign_completion
end

#zerg_swarm_levelObject

Returns the value of attribute zerg_swarm_level.



4
5
6
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 4

def zerg_swarm_level
  @zerg_swarm_level
end

Instance Method Details

#achievementsObject



16
17
18
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 16

def achievements
  @achievements ||= AchievementScraper.new(url: url).scrape
end

#campaign_completionObject



44
45
46
47
48
49
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 44

def campaign_completion
  {
    terran: @terran_campaign_completion,
    zerg: @zerg_campaign_completion
  }
end

#completed_campaign(campaign, difficulty = :normal) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 51

def completed_campaign campaign, difficulty = :normal
  difficulties = [:unearned, :normal, :hard, :brutal]
  ranking = campaign_completion[campaign]
  if difficulties.index(ranking) >= difficulties.index(difficulty)
    true
  else
    false
  end
end

#match_historyObject



32
33
34
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 32

def match_history
  @match_history ||= MatchHistoryScraper.new(url: url).scrape
end

#progress_achievementsObject



24
25
26
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 24

def progress_achievements
  achievements[:progress]
end

#recent_achievementsObject



20
21
22
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 20

def recent_achievements
  achievements[:recent]
end

#scrapeObject



61
62
63
64
65
66
67
68
69
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 61

def scrape
  scraper = ProfileScraper.new(url: @url)
  scraper.scrape

  scraped_data = scraper.output
  scraped_data.each_key do |key|
    self.send "#{key}=", scraped_data[key]
  end
end

#showcase_achievementsObject



28
29
30
# File 'lib/bnet_scraper/starcraft2/profile.rb', line 28

def showcase_achievements
  achievements[:showcase]
end