Class: PlayerSetHistory::Player

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Player

Returns a new instance of Player.



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

def initialize(attributes)
  attributes.each {|key, value| self.send(("#{key}="), value)} 
  @@all << self
end

Instance Attribute Details

#countryObject

Returns the value of attribute country.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def country
  @country
end

#discordObject

Returns the value of attribute discord.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def discord
  @discord
end

#player_idObject

Returns the value of attribute player_id.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def player_id
  @player_id
end

#prefixObject

Returns the value of attribute prefix.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def prefix
  @prefix
end

#pronounObject

Returns the value of attribute pronoun.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def pronoun
  @pronoun
end

#setsObject

Returns the value of attribute sets.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def sets
  @sets
end

#slugObject

Returns the value of attribute slug.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def slug
  @slug
end

#stateObject

Returns the value of attribute state.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def state
  @state
end

#tagObject

Returns the value of attribute tag.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def tag
  @tag
end

#twitchObject

Returns the value of attribute twitch.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def twitch
  @twitch
end

#twitterObject

Returns the value of attribute twitter.



2
3
4
# File 'lib/player_set_history/player.rb', line 2

def twitter
  @twitter
end

Class Method Details

.allObject



10
11
12
# File 'lib/player_set_history/player.rb', line 10

def self.all
  @@all
end

.create_from_json(user_hash) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/player_set_history/player.rb', line 18

def self.create_from_json(user_hash)
  attributes = {
    :pronoun => user_hash["genderPronoun"],
    :state => user_hash["location"]["state"],
    :country => user_hash["location"]["country"],
    :slug => user_hash["discriminator"],
    :player_id => user_hash["player"]["id"],
    :tag => user_hash["player"]["gamerTag"],
    :prefix => user_hash["player"]["prefix"],
  }
  # Links
  unless user_hash["authorizations"] == nil
    user_hash["authorizations"].each do |url|
      
      social = ""
      social = url["url"]
      
      if social != nil
        if social.include?("twitter")
          attributes[:twitter] = social
        elsif social.include?("discord")
          attributes[:discord] = social
        elsif social.include?("twitch")
          attributes[:twitch] = social
        end
      end
    end
  end
  player = PlayerSetHistory::Player.new(attributes)
  return player
end

.create_from_tag(prefix: "", tag:) ⇒ Object



50
51
52
53
54
# File 'lib/player_set_history/player.rb', line 50

def self.create_from_tag(prefix: "", tag:)
  attributes = {:prefix => prefix, :tag => tag}
  player = PlayerSetHistory::Player.new(attributes)
  return player
end

.find_or_create_from_slug(slug, importer) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/player_set_history/player.rb', line 68

def self.find_or_create_from_slug(slug, importer)
  player_index = self.all.index {|x| x.slug == slug}
  
  if player_index == nil
    r_player = importer.import_user_from_sgg(slug)
    player = PlayerSetHistory::Player.create_from_json(r_player)
  else
    player = self.all[player_index]
  end
  
  return player
end

.find_or_create_from_tag(tag:, prefix: "") ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/player_set_history/player.rb', line 56

def self.find_or_create_from_tag(tag: , prefix: "")
  player_index = self.all.index {|x| x.tag.downcase == tag.downcase}

  if player_index == nil
    player = PlayerSetHistory::Player.create_from_tag(tag: tag, prefix: prefix)
  else 
    player = self.all[player_index]
  end
  
  return player
end

Instance Method Details

#add_player_attributes(attributes) ⇒ Object



14
15
16
# File 'lib/player_set_history/player.rb', line 14

def add_player_attributes(attributes)
  attributes.each {|key, value| self.send(("#{key}="), value)}
end

#get_all_setsObject



81
82
83
84
85
86
# File 'lib/player_set_history/player.rb', line 81

def get_all_sets
  sets = PlayerSetHistory::Set.all.select do |set|
    set.players.include?(self)
  end
  return sets
end

#get_all_sets_vs_player(player_tag) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/player_set_history/player.rb', line 88

def get_all_sets_vs_player (player_tag)
  
  sets = self.get_all_sets.select do |set|
    set.score.downcase.include?(player_tag.downcase)
  end
  return sets
end