-
Notifications
You must be signed in to change notification settings - Fork 31
Implementação do teste técnico #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…ranking (the <WORLD> case). Now world will be ignored.
Killer and weapon made optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments, but the biggest problem is the lack of tests.
@match.kills | ||
.joins("INNER JOIN players ON players.id = kills.killer_id OR players.id = kills.killed_id") | ||
.group("players.id","players.name") | ||
.order("frag DESC, deaths") | ||
.pluck( | ||
"players.name", | ||
Arel.sql("SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE 0 END) AS frag"), | ||
Arel.sql("SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@match.kills | |
.joins("INNER JOIN players ON players.id = kills.killer_id OR players.id = kills.killed_id") | |
.group("players.id","players.name") | |
.order("frag DESC, deaths") | |
.pluck( | |
"players.name", | |
Arel.sql("SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE 0 END) AS frag"), | |
Arel.sql("SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths") | |
) | |
@match.kills.joins(:killer) | |
.group('players.id', 'players.name') | |
.order(frag: :desc, deaths: :asc) | |
.select('players.name, '\ | |
'SUM(CASE players.id WHEN kills.killer_id THEN 1 ELSE | |
0 END) AS frag, '\ | |
'SUM(CASE players.id WHEN kills.killed_id THEN 1 ELSE 0 END) AS deaths') |
def find_or_initialize_player(name:) | ||
@players[name] ||= Player.find_or_initialize_by(name: name) | ||
end | ||
|
||
def find_or_initialize_weapon(name:) | ||
@weapons[name] ||= Weapon.find_or_initialize_by(name: name) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation.
self | ||
end | ||
|
||
def create_kill(killed_at:, killer:, killed:, weapon:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to extract this method to its own service.
self | ||
end | ||
|
||
def create_suicide(killed_at:, killed:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to extract this method to its own service.
@@ -0,0 +1,44 @@ | |||
class Match::Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is doing too much.
def validate_match | ||
players_qty = players.size | ||
raise PlayersLimitExceededError, message(players_qty) if players_qty > PLAYERS_LIMIT | ||
end | ||
|
||
def players | ||
(match.kills.map(&:killer) | match.kills.map(&:killed)).compact | ||
end | ||
|
||
def message(players_qty) | ||
"Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation.
end | ||
|
||
def message(players_qty) | ||
"Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Excedded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." | |
"Exceeded limit of #{PLAYERS_LIMIT} players per match: #{players_qty} players." |
|
||
def each_match | ||
@file.each_line do |line| | ||
next if line.blank? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new line after guard clauses.
next if line.blank? | |
next if line.blank? | |
case captures | ||
in { started_at: started_at, code: code } => params | ||
@match_builder = Match::Builder.new | ||
@match_builder.start_match(**params) | ||
in { ended_at: ended_at, code: code } => params | ||
yield @match_builder.end_match(**params).build | ||
in { killed_at: killed_at, killer: killer, killed: killed, weapon: weapon } => params | ||
@match_builder.create_kill(**params) | ||
in { killed_at: killed_at, killed: killed } => params | ||
@match_builder.create_suicide(**params) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the second time that I see someone using a case statement in Ruby, and I don't like it.. 😢 hahaha
It is hard to read. I also like to use regular expressions when it is essentially necessary; they are computationally costly.
def extract_captures(match) | ||
captures = match.named_captures | ||
captures.compact! | ||
captures.transform_keys!(&:to_sym) | ||
captures | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad indentation
Fiz da maneira mais simples possível. Algumas soluções poderiam ser melhoradas, mas foi o que consegui fazer no tempo proposto.
A implementação do importador do arquivo foi feita usando PORO e depois com serviços, isso consta no histórico dos commits.