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 = "month", sum = false) ⇒ Object

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



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

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

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

	if corpus == "livres" && resolution == "month"
		resolution = "year"
	end

	data = group_by_resolution(output, resolution)

	return data
end