Class: Repos::StackOverflow
- Inherits:
-
Object
- Object
- Repos::StackOverflow
- Defined in:
- lib/repocrawler/crawler.rb
Instance Method Summary collapse
-
#get_questions ⇒ Object
get questions from stackexchange.
-
#initialize(gem_name) ⇒ StackOverflow
constructor
A new instance of StackOverflow.
Constructor Details
#initialize(gem_name) ⇒ StackOverflow
Returns a new instance of StackOverflow.
242 243 244 |
# File 'lib/repocrawler/crawler.rb', line 242 def initialize(gem_name) @STACKOVERFLOW_API = "https://api.stackexchange.com/2.2/search/advanced?order=desc&sort=creation&q=#{gem_name}&site=stackoverflow&key=#{ENV['stackoverflow_token']}" end |
Instance Method Details
#get_questions ⇒ Object
get questions from stackexchange
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/repocrawler/crawler.rb', line 247 def get_questions stop_words = [] File.open(File.("../../public/stop_words.txt", File.dirname(__FILE__)), "r") do |f| f.each_line do |line| stop_words << line.gsub(/\n/,"") end end questions = [] fetch_questions = HTTParty.get(@STACKOVERFLOW_API) fetch_questions['items'].each do |q| #don't store stop words good_words = [] q['title'].split(' ').map do |word| if !stop_words.include?(word.downcase) good_words << word end end questions << { 'creation_date' => q['creation_date'], 'title' => good_words, 'views' => q['view_count'] } end questions_word_count = Hash.new(0) questions.each do |question| question['title'].each do |word| questions_word_count[word] += 1 end end questions_word_count = questions_word_count.sort_by { |word, freq| freq }.reverse! [questions, questions_word_count] end |