twords 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/twords.rb +28 -23
  3. data/lib/twords/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7807f5379e15a0aaafe4b95ed3251fa27bb4d330
4
- data.tar.gz: 934074f6e07cc2365959c94ac2f766e8e5d61768
3
+ metadata.gz: a33c7098ea5fe083cfdd02cb0ccfc06d3384df2b
4
+ data.tar.gz: 25ce5cb86c212b64217c5ec264d5dfa80cad9449
5
5
  SHA512:
6
- metadata.gz: 9dc97d9fdc4cd6ea03a2b0533f6073300f023f36ef864e44f1765a7b29259e38affd3d3d56847ff4fb4ced4971c251b1064f69ca3e434e1f239a7f842f16afcd
7
- data.tar.gz: 0c7d53de0314376960f7f75aba920dc82e7dfd7fa03a7a1f8091d4b4da83cffedcecc3c516bc57271db81d8feeab85c4d504f481b22a0e4f3ae9993f8573e6e0
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, :range, :client, :up_to_block, :include_hashtags, :include_uris,
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 is_a_boolean?(boolean)
64
+ raise ArgumentError, 'argument must be a booolean value' unless a_boolean?(boolean)
64
65
  end
65
66
 
66
- def is_a_boolean?(other)
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 recent_tweets
159
- @_recent_tweets ||= timeline.each_with_object([]) do |tweet, memo|
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.sort { |a, b| b.created_at <=> a.created_at }
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) / 86400
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
- recent_tweets.each do |tweet|
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.has_key?(word)
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 recent_tweets_count
194
- @_recent_tweets_count ||= recent_tweets.count
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(filename: nil)
207
- filename = filename || 'twords_report.csv'
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(filename: nil)
216
- filename = filename || 'twords_report.json'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Twords
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg