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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/twords/version.rb +1 -1
  3. data/lib/twords.rb +28 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27f1c65684b3af0b7d96a2987c5d597e1a3e2049
4
- data.tar.gz: 332a52d200691a188ec34d8e902e71c033f64e3f
3
+ metadata.gz: 7807f5379e15a0aaafe4b95ed3251fa27bb4d330
4
+ data.tar.gz: 934074f6e07cc2365959c94ac2f766e8e5d61768
5
5
  SHA512:
6
- metadata.gz: 1419af30473aa0c1dd9f831515c1a5f1a1c8e37cb9f18cdb482fc18bbd7a86d7144fc5e9e01a5d6c2d5b80c586dfc8b64bec18bc8a69f692c0e3520ec7118c6c
7
- data.tar.gz: 4418803ab8a1ba929f274e0897bcdf22a2266757aff02e7b63e6bc55fc62a08f28e2d05c1b50a8c83563669eb438efa4be73542fdcdae75cff5a81c50e8d675c
6
+ metadata.gz: 9dc97d9fdc4cd6ea03a2b0533f6073300f023f36ef864e44f1765a7b29259e38affd3d3d56847ff4fb4ced4971c251b1064f69ca3e434e1f239a7f842f16afcd
7
+ data.tar.gz: 0c7d53de0314376960f7f75aba920dc82e7dfd7fa03a7a1f8091d4b4da83cffedcecc3c516bc57271db81d8feeab85c4d504f481b22a0e4f3ae9993f8573e6e0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Twords
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twords
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg