twords 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/twords/version.rb +1 -1
- data/lib/twords.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7807f5379e15a0aaafe4b95ed3251fa27bb4d330
|
4
|
+
data.tar.gz: 934074f6e07cc2365959c94ac2f766e8e5d61768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dc97d9fdc4cd6ea03a2b0533f6073300f023f36ef864e44f1765a7b29259e38affd3d3d56847ff4fb4ced4971c251b1064f69ca3e434e1f239a7f842f16afcd
|
7
|
+
data.tar.gz: 0c7d53de0314376960f7f75aba920dc82e7dfd7fa03a7a1f8091d4b4da83cffedcecc3c516bc57271db81d8feeab85c4d504f481b22a0e4f3ae9993f8573e6e0
|
data/lib/twords/version.rb
CHANGED
data/lib/twords.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'csv'
|
3
4
|
require 'twitter'
|
4
5
|
require 'uri'
|
5
6
|
|
@@ -192,4 +193,31 @@ class Twords
|
|
192
193
|
def recent_tweets_count
|
193
194
|
@_recent_tweets_count ||= recent_tweets.count
|
194
195
|
end
|
196
|
+
|
197
|
+
def to_csv
|
198
|
+
CSV.generate do |csv|
|
199
|
+
csv << %w[word count]
|
200
|
+
sort_words.each do |word_count|
|
201
|
+
csv << word_count
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def write_to_csv(filename: nil)
|
207
|
+
filename = filename || 'twords_report.csv'
|
208
|
+
write_file(filename, :to_csv)
|
209
|
+
end
|
210
|
+
|
211
|
+
def to_json
|
212
|
+
sort_words.to_h.to_json
|
213
|
+
end
|
214
|
+
|
215
|
+
def write_to_json(filename: nil)
|
216
|
+
filename = filename || 'twords_report.json'
|
217
|
+
write_file(filename, :to_json)
|
218
|
+
end
|
219
|
+
|
220
|
+
def write_file(filename, method)
|
221
|
+
File.open(filename, 'w') { |file| file.write send(method) }
|
222
|
+
end
|
195
223
|
end
|