faker 3.5.2 → 3.5.3

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.
@@ -591,7 +591,7 @@ module Faker
591
591
 
592
592
  def weight_sum(array, weights)
593
593
  sum = 0
594
- (0..weights.size - 1).each do |index|
594
+ (0..(weights.size - 1)).each do |index|
595
595
  sum += (array[index] * weights[index])
596
596
  end
597
597
  sum
@@ -147,7 +147,7 @@ module Faker
147
147
 
148
148
  paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < characters
149
149
 
150
- "#{paragraph[0...characters - 1]}."
150
+ "#{paragraph[0...(characters - 1)]}."
151
151
  end
152
152
  end
153
153
  end
@@ -187,7 +187,7 @@ module Faker
187
187
  def random(exclude: [])
188
188
  method_list = available_methods
189
189
  exclude.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
190
- send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
190
+ send(method_list[Faker::Config.random.rand(0..(method_list.length - 1))])
191
191
  end
192
192
 
193
193
  ##
@@ -194,7 +194,7 @@ module Faker
194
194
 
195
195
  paragraph += " #{paragraph(sentence_count: 3, supplemental: supplemental)}" while paragraph.length < number
196
196
 
197
- "#{paragraph[0...number - 1]}."
197
+ "#{paragraph[0...(number - 1)]}."
198
198
  end
199
199
 
200
200
  ##
@@ -28,7 +28,7 @@ module Faker
28
28
  def emphasis
29
29
  paragraph = Faker::Lorem.paragraph(sentence_count: 3)
30
30
  words = paragraph.split
31
- position = rand(0..words.length - 1)
31
+ position = rand(0..(words.length - 1))
32
32
  formatting = fetch('markdown.emphasis')
33
33
  words[position] = "#{formatting}#{words[position]}#{formatting}"
34
34
  words.join(' ')
@@ -133,7 +133,7 @@ module Faker
133
133
  def random(*args)
134
134
  method_list = available_methods
135
135
  args&.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
136
- send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
136
+ send(method_list[Faker::Config.random.rand(0..(method_list.length - 1))])
137
137
  end
138
138
 
139
139
  ##
@@ -17,6 +17,9 @@ module Faker
17
17
  #
18
18
  # @faker.version 1.7.3
19
19
  def user(include_status: true, include_email: false)
20
+ warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
21
+ will be removed, check the docs for more details.')
22
+
20
23
  user_id = id
21
24
  background_image_url = Faker::LoremFlickr.image(size: '600x400')
22
25
  profile_image_url = Faker::Avatar.image(slug: user_id, size: '48x48')
@@ -81,6 +84,9 @@ module Faker
81
84
  #
82
85
  # @faker.version 1.7.3
83
86
  def status(include_user: true, include_photo: false)
87
+ warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead. Some return attributes \
88
+ will be removed, check the docs for more details.')
89
+
84
90
  status_id = id
85
91
  status = {
86
92
  id: status_id,
@@ -123,6 +129,8 @@ module Faker
123
129
  #
124
130
  # @faker.version 1.7.3
125
131
  def screen_name
132
+ warn('DEPRECATION WARNING: Faker::Twitter is deprecated. Use Faker::X instead.')
133
+
126
134
  Faker::Internet.username(specifier: nil, separators: ['_'])[0...20]
127
135
  end
128
136
 
@@ -204,4 +212,190 @@ module Faker
204
212
  end
205
213
  end
206
214
  end
215
+
216
+ class X < Base
217
+ class << self
218
+ ##
219
+ # Produces a random X user based on X's v2 API.
220
+ #
221
+ # @return [Hash]
222
+ #
223
+ # @example
224
+ # Faker::X.user #=> { data: [{:id=>"8821452687517076614", :name=>"Lincoln Paucek", :screen_name=>"cody"...
225
+ #
226
+ # @faker.version 1.7.3
227
+ def user
228
+ author_id = Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807)
229
+
230
+ {
231
+ data: [
232
+ {
233
+ author_id: author_id.to_s,
234
+ id: id.to_s,
235
+ text: Faker::Lorem.sentence
236
+ }
237
+ ],
238
+ includes: {
239
+ users: [
240
+ {
241
+ public_metrics: {
242
+ followers_count: Faker::Number.between(to: 1, from: 1_000),
243
+ following_count: Faker::Number.between(to: 1, from: 200),
244
+ tweet_count: Faker::Number.between(to: 1, from: 10_000),
245
+ listed_count: Faker::Number.between(to: 1, from: 1_000)
246
+ },
247
+ username: screen_name,
248
+ pinned_tweet_id: Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807).to_s,
249
+ entities: user_entities,
250
+ description: Faker::Lorem.sentence,
251
+ name: Faker::Name.name,
252
+ verified: Faker::Boolean.boolean(true_ratio: 0.1),
253
+ location: Faker::Internet.public_ip_v4_address,
254
+ id: author_id.to_s,
255
+ protected: Faker::Boolean.boolean(true_ratio: 0.1),
256
+ url: url,
257
+ profile_image_url: Faker::Avatar.image(slug: id, size: '48x48'),
258
+ created_at: created_at
259
+ }
260
+ ]
261
+ }
262
+ }
263
+ end
264
+
265
+ ##
266
+ # Produces a random X tweet with default attributes.
267
+ #
268
+ # @param include_user [Boolean] Include user details
269
+ # @param include_media [Boolean] Include user media (photo) details
270
+ # @return [Hash]
271
+ #
272
+ # @example
273
+ # Faker::X.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non."...
274
+ # Faker::X.tweet(include_media: true) # Get a tweet object with a photo media attachment
275
+ # Faker::X.tweet(include_user: true) # Get a tweet object with an user details
276
+ #
277
+ # @faker.version 1.7.3
278
+ def tweet(include_media: false, include_user: false)
279
+ tweet = {}
280
+ tweet_object = tweet_item
281
+ includes = {}
282
+
283
+ if include_media
284
+ media_key = Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807).to_s
285
+
286
+ includes[:media] = media(media_key)
287
+ tweet_object[:attachments] = { media_keys: [media_key] }
288
+ end
289
+
290
+ includes[:users] = user[:includes][:users] if include_user
291
+
292
+ tweet[:data] = [
293
+ tweet_object
294
+ ]
295
+
296
+ unless includes.empty?
297
+ tweet[:includes] = includes
298
+ end
299
+
300
+ tweet
301
+ end
302
+
303
+ ##
304
+ # Produces a random screen_name.
305
+ #
306
+ # @return [String]
307
+ #
308
+ # @example
309
+ # Faker::X.screen_name #=> "audreanne_hackett"
310
+ #
311
+ # @faker.version 1.7.3
312
+ def screen_name
313
+ Faker::Internet.username(specifier: nil, separators: ['_'])[0...20]
314
+ end
315
+
316
+ private
317
+
318
+ def id
319
+ Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807)
320
+ end
321
+
322
+ def created_at
323
+ Faker::Date.between(from: '2006-03-21', to: ::Date.today).to_time.utc.iso8601(3)
324
+ end
325
+
326
+ def url
327
+ "https://t.co/#{Faker::Lorem.characters(number: 10)}"
328
+ end
329
+
330
+ def user_entities
331
+ entities = tweet_entities
332
+
333
+ {
334
+ url: {
335
+ urls: entities[:urls]
336
+ },
337
+ description: {
338
+ hashtags: entities[:hashtags]
339
+ }
340
+ }
341
+ end
342
+
343
+ def tweet_entities
344
+ display_url = Faker::Internet.url(host: 'example.com')
345
+
346
+ {
347
+ urls: [
348
+ {
349
+ start: 0,
350
+ end: 5,
351
+ url: url,
352
+ expanded_url: display_url,
353
+ display_url: display_url.sub('http://', '')
354
+ }
355
+ ],
356
+ hashtags: [
357
+ {
358
+ start: 0,
359
+ end: 5,
360
+ tag: Faker::Lorem.word.capitalize
361
+ }
362
+ ]
363
+ }
364
+ end
365
+
366
+ def media(media_key)
367
+ expanded_url = Faker::LoremFlickr.image(size: '1064x600')
368
+
369
+ [{
370
+ height: Faker::Number.between(to: 1, from: 1000),
371
+ media_key: media_key,
372
+ type: 'photo',
373
+ preview_image_url: expanded_url,
374
+ width: Faker::Number.between(to: 1, from: 2000),
375
+ alt_text: Faker::Lorem.sentence
376
+ }]
377
+ end
378
+
379
+ def tweet_item
380
+ conversation_id = id.to_s
381
+
382
+ {
383
+ id: conversation_id,
384
+ text: Faker::Lorem.sentence,
385
+ lang: sample(%w[en fr es pt it ja]),
386
+ conversation_id: conversation_id,
387
+ created_at: created_at,
388
+ author_id: Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807).to_s,
389
+ public_metrics: {
390
+ retweet_count: Faker::Number.between(to: 1, from: 100),
391
+ reply_count: Faker::Number.between(to: 1, from: 20),
392
+ like_count: Faker::Number.between(to: 1, from: 25),
393
+ quote_count: Faker::Number.between(to: 1, from: 10)
394
+ },
395
+ possibly_sensitive: Faker::Boolean.boolean(true_ratio: 0.1),
396
+ entities: tweet_entities
397
+ }
398
+ end
399
+ end
400
+ end
207
401
  end
@@ -116,7 +116,7 @@ module Faker
116
116
  #
117
117
  # @faker.version 1.8.6
118
118
  def random_type
119
- type_to_use = SIMPLE_TYPES[rand(0..SIMPLE_TYPES.length - 1)]
119
+ type_to_use = SIMPLE_TYPES[rand(0..(SIMPLE_TYPES.length - 1))]
120
120
  case type_to_use
121
121
  when :string
122
122
  rb_string
@@ -136,7 +136,7 @@ module Faker
136
136
  # @faker.version 1.8.6
137
137
  def random_complex_type
138
138
  types = SIMPLE_TYPES + COMPLEX_TYPES
139
- type_to_use = types[rand(0..types.length - 1)]
139
+ type_to_use = types[rand(0..(types.length - 1))]
140
140
  case type_to_use
141
141
  when :string
142
142
  rb_string
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'music'
4
+
5
+ module Faker
6
+ class Music
7
+ class BossaNova < Base
8
+ class << self
9
+ ##
10
+ # Produces the name of a bossa nova artist.
11
+ #
12
+ # @return [String]
13
+ #
14
+ # @example
15
+ # Faker::Music::BossaNova.artist #=> "Tom Jobin"
16
+ #
17
+ # @faker.version 1.8.3
18
+ def artist
19
+ fetch('bossa_nova.artists')
20
+ end
21
+
22
+ ##
23
+ # Produces a bossa nova song.
24
+ #
25
+ # @return [String]
26
+ #
27
+ # @example
28
+ # Faker::Music::BossaNova.song #=> "Chega de Saudade"
29
+ #
30
+ # @faker.version 1.8.3
31
+ def song
32
+ fetch('bossa_nova.songs')
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ include Faker::Deprecator
39
+
40
+ deprecate_generator('BossaNova', Music::BossaNova)
41
+ end
data/lib/faker/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Faker # :nodoc:
4
- VERSION = '3.5.2'
4
+ VERSION = '3.5.3'
5
5
  end