lib/primus.rb in primus_lapus-0.1.1 vs lib/primus.rb in primus_lapus-0.1.2
- old
+ new
@@ -1,40 +1,15 @@
-require "primus/version"
+# frozen_string_literal: true
-module Primus
- class Reorder
- def call(hash)
- is_hash_empty?(hash)
- sort_array
- convert_to_upcase_string
- end
+require 'primus/version'
- private
-
- def is_hash_empty?(hash)
- raise RuntimeError.new("This hash is empty") if hash.empty?
- take_odd_keys(hash)
- end
-
- def take_odd_keys(hash)
- hash.each_with_index { |(key,value), index| array << key if index.odd? }
- end
-
- def sort_array
- array.sort! { |x,y| y <=> x }
- end
-
- def convert_to_upcase_string
- array.each { |c| string << c.upcase }
- string
- end
-
- def array
- @array ||= []
- end
-
- def string
- @string ||= ""
- end
-
+# Takes a hash and returns string of reverse order odd keys
+class Primus
+ def self.call(hash)
+ raise 'This hash is empty' if hash.empty?
+ array = hash.each_with_index.map { |(key), index| key.upcase if index.odd? }.compact
+ array.sort.reverse.join('')
end
end
+
+# add rubo cop, frozen string, revise sort each with index, each_slice,
+# slice_each, call this without caiing .new