lib/sqa/stock.rb in sqa-0.0.14 vs lib/sqa/stock.rb in sqa-0.0.15

- old
+ new

@@ -1,11 +1,8 @@ # lib/sqa/stock.rb -require 'active_support/core_ext/string' # for String#underscore -require 'hashie' # for Hashie::Mash - # SMELL: SQA::Stock is now pretty coupled to the Alpha Vantage # API service. Should that stuff be extracted into a # separate class and injected by the requiring program? class SQA::Stock @@ -99,16 +96,16 @@ # recent closed trading day. # def top return @@top unless @@top.nil? - mash = Hashie::Mash.new( - JSON.parse( - CONNECTION.get( - "/query?function=TOP_GAINERS_LOSERS&apikey=#{Nenv.av_api_key}" - ).to_hash[:body] - ) - ) + a_hash = JSON.parse( + CONNECTION.get( + "/query?function=TOP_GAINERS_LOSERS&apikey=#{Nenv.av_api_key}" + ).to_hash[:body] + ) + + mash = Hashie::Mash.new(a_hash) keys = mash.top_gainers.first.keys %w[top_gainers top_losers most_actively_traded].each do |collection| mash.send(collection).each do |e|