From 473b661c681bc156c09f90158cfb439156e5d77e Mon Sep 17 00:00:00 2001 From: Alexander Azarov Date: Tue, 20 Dec 2016 21:24:05 +0200 Subject: [PATCH] Optimize repetitive code --- lib/legitbot/facebook.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/legitbot/facebook.rb b/lib/legitbot/facebook.rb index cb9f92b..ed6334e 100644 --- a/lib/legitbot/facebook.rb +++ b/lib/legitbot/facebook.rb @@ -11,16 +11,12 @@ class Facebook < BotMatch client = Irrc::Client.new client.query :radb, 'AS32934' results = client.perform - Hash[ - :ipv4 => SegmentTree.new( - results[AS][:ipv4][AS].map { |cidr| - [IPAddr.new(cidr).to_range, true] - }), - :ipv6 => SegmentTree.new( - results[AS][:ipv6][AS].map { |cidr| + + Hash[%i(ipv4 ipv6).map { |k| + [k, SegmentTree.new(results[AS][k][AS].map { |cidr| [IPAddr.new(cidr).to_range, true] - }) - ] + })] + }] end def valid?