Class: Bgg::User
- Inherits:
-
Object
- Object
- Bgg::User
- Defined in:
- lib/bgg/user.rb
Instance Attribute Summary collapse
-
#avatar_link ⇒ Object
readonly
Returns the value of attribute avatar_link.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_login ⇒ Object
readonly
Returns the value of attribute last_login.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#year_registered ⇒ Object
readonly
Returns the value of attribute year_registered.
Class Method Summary collapse
Instance Method Summary collapse
- #collection ⇒ Object
-
#initialize(user_data) ⇒ User
constructor
A new instance of User.
- #play_count ⇒ Object
- #plays ⇒ Object
Constructor Details
#initialize(user_data) ⇒ User
Returns a new instance of User.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bgg/user.rb', line 7 def initialize(user_data) @id = user_data['id'] @first_name = user_data['firstname'][0]['value'] @last_name = user_data['lastname'][0]['value'] @name = user_data['name'] @avatar_link = user_data['avatarlink'][0]['value'] @country = user_data['country'][0]['value'] @last_login = user_data['lastlogin'][0]['value'] @state = user_data['stateorprovince'][0]['value'] @year_registered = user_data['yearregistered'][0]['value'] end |
Instance Attribute Details
#avatar_link ⇒ Object (readonly)
Returns the value of attribute avatar_link.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def avatar_link @avatar_link end |
#country ⇒ Object (readonly)
Returns the value of attribute country.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def country @country end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def first_name @first_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def id @id end |
#last_login ⇒ Object (readonly)
Returns the value of attribute last_login.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def last_login @last_login end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def last_name @last_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def name @name end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def state @state end |
#year_registered ⇒ Object (readonly)
Returns the value of attribute year_registered.
3 4 5 |
# File 'lib/bgg/user.rb', line 3 def year_registered @year_registered end |
Class Method Details
.find_by_id(user_id) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bgg/user.rb', line 20 def self.find_by_id(user_id) user_id = Integer(user_id) if user_id < 1 raise ArgumentError.new('user_id must be greater than zero!') end user_data = BggApi.user({id: user_id}) if user_data['id'].empty? raise ArgumentError.new('User does not exist') end Bgg::User.new(user_data) end |
.find_by_name(user_name) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bgg/user.rb', line 34 def self.find_by_name(user_name) if user_name !~ /^\w+$/ raise ArgumentError.new('find_by_name must be passed a string!') end user_data = BggApi.user({name: user_name}) if user_data['id'].empty? raise ArgumentError.new('User does not exist') end Bgg::User.new(user_data) end |
Instance Method Details
#collection ⇒ Object
52 53 54 |
# File 'lib/bgg/user.rb', line 52 def collection Bgg::Collection.find_by_username(self.name) end |
#play_count ⇒ Object
47 48 49 50 |
# File 'lib/bgg/user.rb', line 47 def play_count some_plays = BggApi.plays({username: self.name, page: 1}) some_plays.fetch('total', 0).to_i end |
#plays ⇒ Object
56 57 58 |
# File 'lib/bgg/user.rb', line 56 def plays Bgg::Plays.find_by_username(self.name) end |