twords 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd0f26ec512e5184542436f0313c827888abed77
4
- data.tar.gz: fc38f75b82aefeac2b695398f22659ebe251743c
3
+ metadata.gz: 201fe822e2fdd8c1ec5168fd73deb7cfb8dd29db
4
+ data.tar.gz: e3b057e402b2b3f1c5f47235de4f687836322c55
5
5
  SHA512:
6
- metadata.gz: 79960eed5ede9ea409a0b60cda01e383fba21d960a6c9112a67e6495d840b78cc26bc5593ee1fdce56ee9d34544b73484ab3de27e78f7f9ad9106b199e9a9f5e
7
- data.tar.gz: 2f1f574ffb732f92a0fa2d7e5b1c1dc4665b2e4bc799e7ff31b16b8598fdee5549b36f2eb0c392a5cd49f84198a5dc911ad559819163559c5b000c2cb59d36f0
6
+ metadata.gz: 0b55531d7030c0fce27b3cd0e54c82f739c7cc3ff5b90596d087a7a8cf73d2ec3b5434c21daed60423b3fb3fcf55f724f6a3bf0dd65f8460348eab92f0a0f8d9
7
+ data.tar.gz: 85ebd69ab5677bf649cb618ae491f9bba4b3868c2030dd6254891bde8939f5509a3ac0e9d6ea2e3530a1cc0834e833d4a4e448d17dd6788cec442b30fd1bc506
data/README.md CHANGED
@@ -22,6 +22,12 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install twords
24
24
 
25
+ ## Documentation
26
+
27
+ [http://rdoc.info/gems/twords][documentation]
28
+
29
+ [documentation]: http://rdoc.info/gems/twords
30
+
25
31
  ## Usage
26
32
 
27
33
  Twords takes a configuration block, and if it doesn't find one it will set the following defaults:
@@ -4,8 +4,36 @@ require 'twitter'
4
4
  require 'twords/twitter_client'
5
5
 
6
6
  class Twords
7
- # Configuration object
7
+ # Configuration object for the Twords namespace. One instance to rule them all.
8
+ # All options can be changed with public setter methods. One Twords::Configuration instance
9
+ # is shared across all objects in the Twords namespace. Changing the configuration will affect
10
+ # all objects, even those that are already instantiated. To set app configuration, do not
11
+ # initialize a Twords::Configuration object directly - nothing will happen.
12
+ # Do it through Twords.config(&block).
13
+ #
14
+ # @see Twords.config
15
+ # @example
16
+ # Twords.config do |config|
17
+ # config.rejects = %w[my us we an w/ because b/c or are this is from
18
+ # be on the for to and at our of in rt a with &
19
+ # that it by as if was]
20
+ #
21
+ # config.range = 30
22
+ # config.up_to { Time.now }
23
+ # config.include_hashtags = false
24
+ # config.include_uris = false
25
+ # config.include_mentions = false
26
+ #
27
+ # config.twitter_client do |twitter|
28
+ # twitter.consumer_key = ENV['TWITTER_CONSUMER_KEY']
29
+ # twitter.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
30
+ # twitter.access_token = ENV['TWITTER_ACCESS_TOKEN']
31
+ # twitter.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
32
+ # end
33
+ # end
8
34
  class Configuration
35
+ # Default words to ignore. Strings must match exactly and are checked with
36
+ # Array#include?
9
37
  DEFAULT_REJECTS = %w[
10
38
  my us we an w/ because
11
39
  b/c or are this is from
@@ -14,6 +42,10 @@ class Twords
14
42
  that it by as if was
15
43
  ].freeze
16
44
 
45
+ # Default configuration block to pass to Twords::TwitterClient.new.
46
+ # Feel free to customize the variables in a configuration block of your own,
47
+ # but never hard code the values. Or just make the values available at the default
48
+ # locations.
17
49
  DEFAULT_TWITTER_CONFIG = lambda do |twitter|
18
50
  twitter.consumer_key = ENV['TWITTER_CONSUMER_KEY']
19
51
  twitter.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
@@ -21,6 +53,8 @@ class Twords
21
53
  twitter.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET']
22
54
  end
23
55
 
56
+ # Full set of default options that will be passed to the Configuration object
57
+ # on initialization and reset.
24
58
  DEFAULT_OPTIONS = {
25
59
  include_uris: false,
26
60
  include_hashtags: false,
@@ -36,42 +70,77 @@ class Twords
36
70
 
37
71
  attr_accessor :range
38
72
 
73
+ # Initializes a new Twords::Configuration object with default configuration.
74
+ #
75
+ # @api public
76
+ # @return [Twords::Configuration]
39
77
  def initialize
40
78
  set_defaults
41
79
  end
42
80
 
81
+ # Resets all configuration options to "factory" default settings.
82
+ #
83
+ # @api public
84
+ # @return [Twords::Configuration]
85
+ # @see Twords.reset_config!
43
86
  def reset!
44
87
  tap { set_defaults }
45
88
  end
46
89
 
90
+ # Configure a new Twords::TwitterClient with a configuration block.
91
+ # If no block is given the existing client is returned unchanged.
92
+ #
93
+ # @api public
94
+ # @return [Twords::TwitterClient]
47
95
  def twitter_client(&block)
48
- @client = TwitterClient.new(&block)
96
+ @client = TwitterClient.new(&block) if block_given?
97
+ @client
49
98
  end
50
99
 
100
+ # Set the words to be skipped during analysis.
101
+ #
102
+ # @param args [Array<String>] an indefinite list of words to ignore
51
103
  def rejects=(*args)
52
- @rejects = args.flatten
104
+ @rejects = args.flatten.map(&:to_s)
53
105
  end
54
106
 
107
+ # Set whether hashtags should be counted. If true, any word beginning with "#" will be ignored.
108
+ #
109
+ # @param boolean [true, false] will raise an error if the value is not a Boolean value
55
110
  def include_hashtags=(boolean)
56
111
  not_a_boolean_error(boolean)
57
112
  @include_hashtags = boolean
58
113
  end
59
114
 
115
+ # Set whether URIs should be counted. If true, uses URI#regexp to match.
116
+ #
117
+ # @param boolean [true, false] will raise an error if the value is not a Boolean value
60
118
  def include_uris=(boolean)
61
119
  not_a_boolean_error(boolean)
62
120
  @include_uris = boolean
63
121
  end
64
122
  alias include_urls= include_uris=
65
123
 
124
+ # Set whether @-mentions should be counted. If true, any word beginning with "@" will be ignored.
125
+ #
126
+ # @param boolean [true, false] will raise an error if the value is not a Boolean value
66
127
  def include_mentions=(boolean)
67
128
  not_a_boolean_error(boolean)
68
129
  @include_mentions = boolean
69
130
  end
70
131
 
132
+ # Takes a block and stores for lazy evaluation to define the end of the time range being checked.
133
+ # The return value of the block must respond to #to_time and return a Time object when called.
134
+ #
135
+ # @return [Proc]
71
136
  def up_to(&time_block)
72
137
  @up_to_block = time_block
73
138
  end
74
139
 
140
+ # Calls the Proc value of #up_to_block and calls #to_time on the return value. Expects a Time object
141
+ # to be returned.
142
+ #
143
+ # @return [Time]
75
144
  def up_to_time
76
145
  up_to_block.call.to_time
77
146
  end
@@ -150,8 +150,8 @@ class Twords
150
150
  #
151
151
  # @api public
152
152
  # @return [Integer] representing the byte count of the file
153
- # @param opts [Hash] customizable file writing options. All but :filename are passed to File#open
154
- # @option opts [String] :filename A relative pathname to define the destination of the new file
153
+ # @param opts [Hash] File writing options. All except for :filename are passed to File#open.
154
+ # @option opts [String] :filename A relative pathname. Defaults to 'twords_report.csv'
155
155
  def write_to_csv(opts = {})
156
156
  filename = opts.fetch(:filename) { 'twords_report.csv' }
157
157
  write_file(filename, :to_csv, opts)
@@ -170,8 +170,8 @@ class Twords
170
170
  #
171
171
  # @api public
172
172
  # @return [Integer] representing the byte count of the file
173
- # @param opts [Hash] customizable file writing options. All but :filename are passed to File#open
174
- # @option opts [String] :filename A relative pathname to define the destination of the new file
173
+ # @param opts [Hash] customizable file writing options. All but :filename arepassed to File#open
174
+ # @option opts [String] :filename A relative pathname. Defaults to 'twords_report.json'
175
175
  def write_to_json(opts = {})
176
176
  filename = opts.fetch(:filename) { 'twords_report.json' }
177
177
  write_file(filename, :to_json, opts)
@@ -7,10 +7,10 @@ class Twords
7
7
  class TwitterClient
8
8
  include ConfigAccessible
9
9
 
10
- # A Twitter::REST::Client that provides an interface to the Twitter API
10
+ # A Twitter::REST::Client that provides a direct interface to the Twitter API
11
11
  #
12
12
  # @api public
13
- # @returns [Twitter::REST::Client]
13
+ # @return [Twitter::REST::Client]
14
14
  attr_reader :client
15
15
 
16
16
  # Initializes a new Twords::TwitterClient object and assigns to the @client instance variable
@@ -25,6 +25,7 @@ class Twords
25
25
  # @api public
26
26
  # for block { |twitter| ... }
27
27
  # @yield [Twitter::REST::Client] yields the Twitter::REST::Client for configuration
28
+ # @see Twords::Configuration#twitter_client
28
29
  # @see https://github.com/sferik/twitter#configuration
29
30
  def initialize(&block)
30
31
  @client = Twitter::REST::Client.new(&block)
@@ -35,6 +36,7 @@ class Twords
35
36
  #
36
37
  # @api public
37
38
  # @param screen_names [Array<String>] the twitter screen names from which to pull the tweets
39
+ # @return [Array<Twitter::Tweet>]
38
40
  def filter_tweets(screen_names)
39
41
  full_timeline(screen_names).each_with_object([]) do |tweet, memo|
40
42
  next if tweet.created_at > up_to_time
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Twords
4
- VERSION = '0.2.1'.freeze
4
+ # The current gem version
5
+ VERSION = '0.2.2'.freeze
5
6
  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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg