Skip to content

Commit

Permalink
Typing for ETF2LProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Arie committed Aug 16, 2024
1 parent d697a7f commit bc5d78c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/models/etf2l_profile.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,53 @@
# frozen_string_literal: true
# typed: true

class Etf2lProfile
extend T::Sig
attr_accessor :json

sig { params(profile_body: String).void }
def initialize(profile_body)
@json = JSON.parse(profile_body)
end

sig { returns(T.nilable(String)) }
def name
json.dig('player', 'name')
end

sig { returns(T::Boolean) }
def banned?
active_bans.any?
end

sig { returns(T.nilable(String)) }
def ban_reason
return nil if active_bans.none?

active_bans.map { |b| b['reason'] }.join(', ')
end

sig { returns(T.nilable(String)) }
def ban_expires_at
return nil if active_bans.none?

active_bans.map { |b| Time.at(b['end']).to_date }.join(', ')
end

sig { returns(T.nilable(Etf2lProfile)) }
def self.fetch(steam_uid)
response_body = Etf2lApi.profile(steam_uid)
new(response_body) if response_body
end

sig { returns(String) }
def self.league_name
'ETF2L'
end

private

sig { returns(T::Array[Hash]) }
def active_bans
@active_bans ||= begin
now = Time.now.to_i
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
# typed: false
# typed: true

class User < ActiveRecord::Base
extend T::Sig
Expand Down

0 comments on commit bc5d78c

Please sign in to comment.