26 lines
546 B
Ruby
26 lines
546 B
Ruby
require 'json'
|
|
|
|
eff = JSON.parse(File.read("src/types.json"))
|
|
|
|
def make_branches(type, defenders, efficacy)
|
|
if defenders.empty?
|
|
[]
|
|
else
|
|
["(#{type}, #{defenders.join(' | ')}) => #{efficacy},"]
|
|
end
|
|
end
|
|
|
|
branches = eff.flat_map do |eff|
|
|
type = eff['name']
|
|
[
|
|
*make_branches(type, eff['immunes'], 'Zero'),
|
|
*make_branches(type, eff['weaknesses'], 'Weak'),
|
|
*make_branches(type, eff['strengths'], 'Strong'),
|
|
]
|
|
end
|
|
|
|
puts "match (self, defender) {
|
|
#{branches.join("\n ")}
|
|
#{make_branches('_', ['_'], 'Neutral')[0]}
|
|
}"
|