word_salad 2.0.0 → 3.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 684b5abb322dfe9d2cacb4d9aa383f1f14a6e287c98ef8bc6dcb86f6b5b65a5b
4
+ data.tar.gz: e9b55115b7f66b36d740bc4f02d771d7e6c52f5d8cab09fd31fee112caf2f125
5
+ SHA512:
6
+ metadata.gz: 407ac779a10724569d94c3d527f59d54fa4febb162b0a165b840b0b961f67ba621cede50f514aa6291044d9dc513c61b27d647cd8e2cc7e723e5440b588bd692
7
+ data.tar.gz: 7ec4aecdb6f801fb255b318146994c8021b8d8a4990b1cb9048bffd27b229887733d57bcc21f6e5cb7172be9740758535ac859e542e8e7cd479de515f8a7c199
@@ -1,47 +1,51 @@
1
- class Fixnum
1
+ # frozen_string_literal: true
2
2
 
3
- # Returns +num+ random words from the dictionary.
4
- def words
5
- dict = WordSalad.dictionary
6
- (1..self).to_a.map do |x|
7
- WordSalad.words[rand(WordSalad.size)].strip
8
- end
9
- end
3
+ %w[word words sentence sentences paragraph paragraphs].each do |meth|
4
+ raise "#{meth} is already defined in Integer class" if Integer.method_defined?(meth)
5
+ end
10
6
 
7
+ # extends the build in Integer class
8
+ class Integer
11
9
  # Returns 1 random word
12
10
  def word
13
11
  1.words.first
14
12
  end
15
13
 
14
+ # Returns 1 sentence of random words about +size+ long
15
+ def sentence(size = 10)
16
+ 1.sentences(size).first
17
+ end
18
+
19
+ # Returns 1 paragraph of +psize+ sentences,
20
+ # each about +ssize+ words long
21
+ def paragraph(psize = 5, ssize = 10)
22
+ 1.paragraphs(psize, ssize).first
23
+ end
24
+
25
+ # Returns +num+ random words from the dictionary.
26
+ def words
27
+ WordSalad.dictionary
28
+ (1..self).to_a.map do |_x|
29
+ WordSalad.words[rand(WordSalad.size)].strip
30
+ end
31
+ end
32
+
16
33
  # Returns +num+ sentences of random words about +size+ long
17
- def sentences(size=10)
18
- (1..self).to_a.map do |x|
19
- variance = rand(size/3 + 1)
20
- variance = 0 - variance if rand(2) == 0 # plus or minus
34
+ def sentences(size = 10)
35
+ (1..self).to_a.map do |_x|
36
+ variance = rand((size / 3) + 1)
37
+ variance = 0 - variance if rand(2).zero? # plus or minus
21
38
  w = (size + variance).words
22
39
  w[0].capitalize!
23
- w.join(' ') + '.'
40
+ "#{w.join(' ')}."
24
41
  end
25
42
  end
26
43
 
27
- # Returns 1 sentence of random words about +size+ long
28
- def sentence(size=10)
29
- 1.sentences(size).first
30
- end
31
-
32
44
  # Returns +num+ paragraphs of +psize+ sentences,
33
45
  # each about +ssize+ words long
34
- def paragraphs(psize=5, ssize=10)
35
- (1..self).to_a.map do |x|
46
+ def paragraphs(psize = 5, ssize = 10)
47
+ (1..self).to_a.map do |_x|
36
48
  psize.sentences(ssize).join(' ')
37
49
  end
38
50
  end
39
-
40
- # Returns 1 paragraph of +psize+ sentences,
41
- # each about +ssize+ words long
42
- def paragraph(psize=5, ssize=10)
43
- 1.paragraphs(psize, ssize).first
44
- end
45
-
46
51
  end
47
-
data/lib/word_salad.rb CHANGED
@@ -1,20 +1,28 @@
1
- require "word_salad/core_ext"
1
+ # frozen_string_literal: true
2
2
 
3
+ # This module generats random English words
3
4
  module WordSalad
5
+ class << self
6
+ # the dictionary as a File object
7
+ def dictionary
8
+ @dictionary ||=
9
+ File.open(File.join(File.dirname(__FILE__), 'word_salad/dictionary'))
10
+ end
4
11
 
5
- # the dictionary as a File object
6
- def self.dictionary
7
- open(File.join(File.dirname(__FILE__), "word_salad/dictionary"))
8
- end
12
+ def dictionary_path=(filename)
13
+ @dictionary = filename
14
+ end
9
15
 
10
- # all the words in the dictionary
11
- def self.words
12
- IO.readlines(self.dictionary)
13
- end
16
+ # all the words in the dictionary
17
+ def words
18
+ File.readlines(dictionary)
19
+ end
14
20
 
15
- # the number of words in the dictionary
16
- def self.size
17
- @size ||= self.words.size
21
+ # the number of words in the dictionary
22
+ def size
23
+ @size ||= words.size
24
+ end
18
25
  end
19
-
20
26
  end
27
+
28
+ require 'word_salad/core_ext'
metadata CHANGED
@@ -1,78 +1,75 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: word_salad
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 2
7
- - 0
8
- - 0
9
- version: 2.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Alex Vollmer
13
8
  - Alice Brown
14
- autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2011-02-17 00:00:00 -05:00
19
- default_executable:
20
- dependencies: []
21
-
22
- description: Word Salad is a very simple Ruby library for generating random strings of English words based on a list of basic english words.
23
- email:
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.8'
41
+ description: Word Salad is a very simple Ruby library for generating random strings
42
+ of English words based on a list of basic english words.
43
+ email:
24
44
  - alex.vollmer@gmail.com
25
45
  - alice@alum.mit.edu
26
46
  executables: []
27
-
28
47
  extensions: []
29
-
30
48
  extra_rdoc_files: []
31
-
32
- files:
33
- - .gitignore
34
- - Gemfile
35
- - History.txt
36
- - README.txt
37
- - Rakefile
38
- - lib/version.rb
49
+ files:
39
50
  - lib/word_salad.rb
40
51
  - lib/word_salad/core_ext.rb
41
52
  - lib/word_salad/dictionary
42
- - lib/word_salad/version.rb
43
- - spec/word_salad_spec.rb
44
- - word_salad.gemspec
45
- has_rdoc: true
46
53
  homepage: https://github.com/ambtus/word_salad
47
- licenses: []
48
-
49
- post_install_message:
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ rubygems_mfa_required: 'true'
50
58
  rdoc_options: []
51
-
52
- require_paths:
59
+ require_paths:
53
60
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
57
63
  - - ">="
58
- - !ruby/object:Gem::Version
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
64
+ - !ruby/object:Gem::Version
65
+ version: '3.0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
65
68
  - - ">="
66
- - !ruby/object:Gem::Version
67
- segments:
68
- - 0
69
- version: "0"
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
70
71
  requirements: []
71
-
72
- rubyforge_project: word_salad
73
- rubygems_version: 1.3.7
74
- signing_key:
75
- specification_version: 3
72
+ rubygems_version: 3.7.2
73
+ specification_version: 4
76
74
  summary: Generate strings of random English text
77
- test_files:
78
- - spec/word_salad_spec.rb
75
+ test_files: []
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in word_salad.gemspec
4
- gemspec
data/History.txt DELETED
@@ -1,13 +0,0 @@
1
- === 1.0.0 / 2009-11-07
2
-
3
- * Happy Birthday Word Salad!
4
-
5
- === 2.0.0 / 2011-02-17
6
-
7
- * switched to included wordlist for more basic words
8
- * switched singular methods to strings instead of arrays
9
- * made the variance bigger for sentence length
10
- * published gem to Rubygems
11
- * fixed bugs
12
- ** EOFError: end of file reached
13
- ** NoMethodError: undefined method `words' for 2.6187173419804153:Float
data/README.txt DELETED
@@ -1,48 +0,0 @@
1
- = Word Salad
2
-
3
- == DESCRIPTION:
4
-
5
- Word Salad is a very simple Ruby library for generating random strings
6
- of English words based on a list of basic english words. Words retrieved
7
- from http://www.langmaker.com/wordlist/basiclex.htm
8
-
9
- == SYNOPSIS:
10
-
11
- WordSalad adds six methods to the <tt>Fixnum</tt> class.
12
-
13
- 1.word ==> "quite"
14
- 5.words ==> ["stone", "bent", "kick", "name", "event"]
15
- 1.sentence => "Take past even rice land red open name engine grass thick pen."
16
- 3.sentences(5) ==> ["Move mass increase fact step quite.", "Clock shirt pocket mountain drain.", "Before fat group such."]
17
- 1.paragraph(5, 5) => "Belief same minute market control. Stamp sand stocking ant angle. Grip form distribution up. Leaf blue committee camera test. Event detail addition point trousers be."
18
- 2.paragraphs(2, 3) ==> ["Disgust idea bucket. Branch sail right.", "Cotton root discussion. Grey thumb.", "Lift minute pipe cake. Any scale.", "Size take gun. Not bell smash out."]
19
-
20
- == INSTALL:
21
-
22
- sudo gem install word_salad
23
-
24
- == LICENSE:
25
-
26
- (The MIT License)
27
-
28
- Copyright (c) 2008 Alex Vollmer
29
- Copyright (c) 2011 Alice Brown
30
-
31
- Permission is hereby granted, free of charge, to any person obtaining
32
- a copy of this software and associated documentation files (the
33
- 'Software'), to deal in the Software without restriction, including
34
- without limitation the rights to use, copy, modify, merge, publish,
35
- distribute, sublicense, and/or sell copies of the Software, and to
36
- permit persons to whom the Software is furnished to do so, subject to
37
- the following conditions:
38
-
39
- The above copyright notice and this permission notice shall be
40
- included in all copies or substantial portions of the Software.
41
-
42
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module .
2
- VERSION = "2.0.0"
3
- end
@@ -1,3 +0,0 @@
1
- module WordSalad
2
- VERSION = "2.0.0"
3
- end
@@ -1,98 +0,0 @@
1
- require "fileutils"
2
- require "tempfile"
3
- require "rubygems"
4
- require "spec"
5
-
6
- $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
7
- require "word_salad"
8
-
9
- describe WordSalad do
10
- describe "generating random words" do
11
- it "should return an array of the right size" do
12
- w = 5.words
13
- w.should be_kind_of(Array)
14
- w.size.should eql(5)
15
- w.each do |word|
16
- word.should be_kind_of(String)
17
- end
18
- end
19
-
20
- it "should respond to the singular version too" do
21
- w = 1.word
22
- w.should be_kind_of(Array)
23
- w.size.should == 1
24
- w.first.should be_kind_of(String)
25
- end
26
- end
27
-
28
- describe "generating random sentences" do
29
- it "should return an array of sentences" do
30
- s = 5.sentences
31
- s.should be_kind_of(Array)
32
- s.size.should == 5
33
- s.each do |sent|
34
- sent.should be_kind_of(String)
35
- sent.should match(/^[A-Z].*\.$/)
36
- sent.split(' ').size.should be_close(10, 2)
37
- end
38
- end
39
-
40
- it "should respond to the singular version too" do
41
- s = 1.sentence
42
- s.should be_kind_of(Array)
43
- s.size.should == 1
44
- end
45
- end
46
-
47
- describe "generating random paragraphs" do
48
- it "should return an array of paragraphs" do
49
- p = 5.paragraphs
50
- p.should be_kind_of(Array)
51
- p.size.should == 5
52
- p.each do |para|
53
- para.should be_kind_of(String)
54
- s = para.split('.')
55
- s.size.should == 5
56
- s.each do |sent|
57
- sent.split(' ').size.should be_close(10, 2)
58
- end
59
- end
60
- end
61
-
62
- it "should respond to singular version too" do
63
- p = 1.paragraph
64
- p.should be_kind_of(Array)
65
- p.size.should == 1
66
- end
67
- end
68
-
69
- describe 'overriding the default dictionary path' do
70
- before(:each) do
71
- @tmpfile = Tempfile.new "word_salad"
72
- 2000.times { @tmpfile << "alpha\n" }
73
- @tmpfile.close
74
- WordSalad.dictionary_path = @tmpfile.path
75
- end
76
-
77
- it 'should work for words' do
78
- w = 5.words
79
- w.each { |e| e.should == "alpha" }
80
- end
81
-
82
- it 'should work for sentences' do
83
- s = 5.sentences
84
- s.each do |sent|
85
- sent.split(' ').each { |e| e.downcase.should match(/alpha/) }
86
- end
87
- end
88
-
89
- it 'should work for paragraphs' do
90
- p = 5.paragraphs
91
- p.each do |para|
92
- para.split('.').each do |sent|
93
- sent.split(' ').each { |e| e.downcase.should match(/alpha/) }
94
- end
95
- end
96
- end
97
- end
98
- end
data/word_salad.gemspec DELETED
@@ -1,21 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "word_salad/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "word_salad"
7
- s.version = WordSalad::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Alex Vollmer", "Alice Brown"]
10
- s.email = ["alex.vollmer@gmail.com", "alice@alum.mit.edu"]
11
- s.homepage = "https://github.com/ambtus/word_salad"
12
- s.summary = %q{Generate strings of random English text}
13
- s.description = %q{Word Salad is a very simple Ruby library for generating random strings of English words based on a list of basic english words.}
14
-
15
- s.rubyforge_project = "word_salad"
16
-
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
21
- end