twords 0.1.5 → 0.1.6
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.rb +28 -23
- data/lib/twords/version.rb +1 -1
- 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: a33c7098ea5fe083cfdd02cb0ccfc06d3384df2b
|
4
|
+
data.tar.gz: 25ce5cb86c212b64217c5ec264d5dfa80cad9449
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df178f0f3bff88225f992838fcd8479df2c9e3c2ccb768e9daf98d1440716a5f6e13956d86a409063f82551e602d0a1f96a15390b5cb8538e1f1afcde59bf4ca
|
7
|
+
data.tar.gz: '04316495bec126d47904cf9581bd12dd8a679e5c9a58d8f2a8a2de9b3ecef4b8196e2da1d48d18fff6b70e8d7006b5006046e1b16db828b278608aa81358ee73'
|
data/lib/twords.rb
CHANGED
@@ -28,8 +28,9 @@ require 'twords/version'
|
|
28
28
|
# # => { "butts"=>35, "poo"=>32, "pups"=>28, ... }
|
29
29
|
class Twords
|
30
30
|
class << self
|
31
|
-
attr_reader :rejects, :
|
31
|
+
attr_reader :rejects, :client, :up_to_block, :include_hashtags, :include_uris,
|
32
32
|
:include_mentions
|
33
|
+
attr_accessor :range
|
33
34
|
|
34
35
|
def config
|
35
36
|
yield self
|
@@ -60,17 +61,13 @@ class Twords
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def not_a_boolean_error(boolean)
|
63
|
-
raise ArgumentError, 'argument must be a booolean value' unless
|
64
|
+
raise ArgumentError, 'argument must be a booolean value' unless a_boolean?(boolean)
|
64
65
|
end
|
65
66
|
|
66
|
-
def
|
67
|
+
def a_boolean?(other)
|
67
68
|
[true, false].include?(other)
|
68
69
|
end
|
69
70
|
|
70
|
-
def range=(integer)
|
71
|
-
@range = integer
|
72
|
-
end
|
73
|
-
|
74
71
|
def up_to(&time_block)
|
75
72
|
@up_to_block = time_block
|
76
73
|
end
|
@@ -155,23 +152,31 @@ class Twords
|
|
155
152
|
fetch_older_tweets(timeline, screen_name)
|
156
153
|
end
|
157
154
|
|
158
|
-
def
|
159
|
-
@
|
155
|
+
def tweets
|
156
|
+
@_tweets ||= timeline.each_with_object([]) do |tweet, memo|
|
160
157
|
memo << tweet if age_of_tweet_in_days(tweet) <= range
|
161
|
-
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def sort_tweets
|
162
|
+
tweets.sort { |a, b| b.created_at <=> a.created_at }
|
163
|
+
end
|
164
|
+
|
165
|
+
def sort_tweets!
|
166
|
+
tweets.sort! { |a, b| b.created_at <=> a.created_at }
|
162
167
|
end
|
163
168
|
|
164
169
|
def age_of_tweet_in_days(tweet)
|
165
|
-
(self.class.up_to_block.call.to_time - tweet.created_at) /
|
170
|
+
(self.class.up_to_block.call.to_time - tweet.created_at) / 86_400
|
166
171
|
end
|
167
172
|
|
168
173
|
def count_words
|
169
174
|
words.clear
|
170
|
-
|
175
|
+
tweets.each do |tweet|
|
171
176
|
words_array = tweet.attrs[:full_text].downcase.split(' ')
|
172
177
|
words_array.each do |word|
|
173
178
|
next if should_be_skipped?(word)
|
174
|
-
if words.
|
179
|
+
if words.key?(word)
|
175
180
|
words[word] += 1
|
176
181
|
else
|
177
182
|
words[word] = 1
|
@@ -190,8 +195,8 @@ class Twords
|
|
190
195
|
audit
|
191
196
|
end
|
192
197
|
|
193
|
-
def
|
194
|
-
@
|
198
|
+
def tweets_count
|
199
|
+
@_tweets_count ||= tweets.count
|
195
200
|
end
|
196
201
|
|
197
202
|
def to_csv
|
@@ -203,21 +208,21 @@ class Twords
|
|
203
208
|
end
|
204
209
|
end
|
205
210
|
|
206
|
-
def write_to_csv(
|
207
|
-
filename = filename
|
208
|
-
write_file(filename, :to_csv)
|
211
|
+
def write_to_csv(opts = {})
|
212
|
+
filename = opts.fetch(:filename) { 'twords_report.csv' }
|
213
|
+
write_file(filename, :to_csv, opts)
|
209
214
|
end
|
210
215
|
|
211
216
|
def to_json
|
212
217
|
sort_words.to_h.to_json
|
213
218
|
end
|
214
219
|
|
215
|
-
def write_to_json(
|
216
|
-
filename = filename
|
217
|
-
write_file(filename, :to_json)
|
220
|
+
def write_to_json(opts = {})
|
221
|
+
filename = opts.fetch(:filename) { 'twords_report.json' }
|
222
|
+
write_file(filename, :to_json, opts)
|
218
223
|
end
|
219
224
|
|
220
|
-
def write_file(filename, method)
|
221
|
-
File.open(filename, 'w') { |file| file.write send(method) }
|
225
|
+
def write_file(filename, method, opts = {})
|
226
|
+
File.open(filename, 'w', opts) { |file| file.write send(method) }
|
222
227
|
end
|
223
228
|
end
|
data/lib/twords/version.rb
CHANGED