Class: Gallicagram

Inherits:
Object
  • Object
show all
Defined in:
lib/gallicagram.rb

Class Method Summary collapse

Class Method Details

.search(query, corpus = "lemonde", start_date = "1900", end_date = "2000", resolution = "annee", sum = false) ⇒ Object

query = string or array of strings corpus = [“lemonde”,“livres”,“presse”] resolution = [“mois”, “annee”]



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gallicagram.rb', line 10

def self.search(query,corpus="lemonde",start_date="1900",end_date="2000",resolution="annee",sum=false)

	query = [query] unless query.kind_of?(Array)
	output = ""
	query.each_with_index do |word, index|
		query = format_query(word, sum)
		if corpus == "livres" && resolution == "mois"
			resolution = "annee"
		end
		response = call_api(word, corpus, start_date, end_date, resolution)
		unless index == 0
			response = response.gsub("n,gram,annee,mois,jour,total", "\n").strip
		end
		output << response
	end

	data = CSV.parse(output, :headers => true)

	return data
end