random-word 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -11,4 +11,7 @@ group :development do
11
11
  gem "bundler", "~> 1.0.0"
12
12
  gem "jeweler", "~> 1.6.2"
13
13
  gem "rcov", ">= 0"
14
+ gem "machinist", ">=2.0.0.beta2"
15
+ gem "activesupport"
16
+ gem "i18n"
14
17
  end
@@ -0,0 +1,13 @@
1
+ 1.1
2
+ ----
3
+ * Machinist serial word support
4
+
5
+ 1.0.1
6
+ ----
7
+ * Added examples to readme
8
+
9
+ 1.0
10
+ ----
11
+ * initial version
12
+ * random noun enumerator
13
+ * random adjective enumerator
@@ -6,6 +6,30 @@ library uses a large list (the wordnet corpus) of english words and
6
6
  provides an enumerator interface to that corpus that will return the
7
7
  words in a random order without repeats.
8
8
 
9
+ Examples
10
+ ----
11
+
12
+ ### General use
13
+
14
+ Random.adjs.next #=> "pugnacious"
15
+ Random.nouns.next #=> "audience"
16
+
17
+ ### Factory Girl
18
+
19
+ Factory.define(:user) do |u|
20
+ u.name "#{RandomWord.adjs.next} User"
21
+ u.email {|u| "#{u.name.gsub(/ +/, '.')}@example.com"
22
+ end
23
+
24
+ Factory(:user) #=>
25
+
26
+ ### Machinist
27
+
28
+ User.blueprint do
29
+ name { "#{sw.capitalize} User" }
30
+ email { "#{sw}.user@example.com" }
31
+ end
32
+
9
33
  Contributing to random-word
10
34
  ----
11
35
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1 +1,2 @@
1
1
  require 'random_word'
2
+ require 'random_word/machinist' if defined?(Machinist)
@@ -1,10 +1,16 @@
1
1
  require 'set'
2
+ require 'pathname'
2
3
 
4
+ # Provides random, non-repeating enumerators of a large list of
5
+ # english words. For example"
6
+ #
7
+ # RandomWord.adjs.next #=> "strengthened"
8
+ #
3
9
  module RandomWord
4
10
  module EachRandomly
5
11
  def each_randomly(&blk)
6
12
  used = Set.new
7
-
13
+
8
14
  while true
9
15
  idx = next_unused_idx(used)
10
16
  used << idx
@@ -14,7 +20,7 @@ module RandomWord
14
20
  rescue OutOfWords
15
21
  # we are done.
16
22
  end
17
-
23
+
18
24
  private
19
25
  def next_unused_idx(used)
20
26
  idx = rand(length)
@@ -23,29 +29,38 @@ module RandomWord
23
29
  raise OutOfWords if try > 1000
24
30
  idx = rand(length)
25
31
  try += 1
26
- end
27
-
32
+ end
33
+
28
34
  idx
29
35
  end
30
36
  class OutOfWords < Exception; end
31
37
  end
32
38
 
33
39
  class << self
34
- def enumerator(word_list)
35
- word_list.extend EachRandomly
36
- Enumerator.new(word_list, :each_randomly)
37
- end
38
-
39
40
 
41
+ # Random noun enumerator
42
+ #
43
+ # @return [Enumerator]
40
44
  def nouns
41
45
  @nouns ||= enumerator(load_word_list("nouns.dat"))
42
46
  end
43
47
 
48
+ # Random adjective enumerator
49
+ #
50
+ # @return [Enumerator]
44
51
  def adjs
45
52
  @adjs ||= enumerator(load_word_list("adjs.dat"))
46
53
  end
47
54
 
55
+ # Create a random, non-repeating enumerator for a list of words
56
+ # (or anything really).
57
+ def enumerator(word_list)
58
+ word_list.extend EachRandomly
59
+ Enumerator.new(word_list, :each_randomly)
60
+ end
61
+
48
62
  protected
63
+
49
64
  def load_word_list(name)
50
65
  data_root = Pathname(File.dirname(__FILE__)) + "../data"
51
66
  File.open(data_root + name){|f| Marshal.load(f)}
@@ -0,0 +1,27 @@
1
+ module RandomWord
2
+ module Machinist
3
+ # The serial word for the object being manufactured.
4
+ def serial_word
5
+ @serial_word ||= RandomWord.adjs.next
6
+ end
7
+ alias_method :sw, :serial_word
8
+
9
+ # The serial adjective for the object being manufactured.
10
+ def serial_adj
11
+ serial_word
12
+ end
13
+
14
+ # The serial noun for the object being manufactured.
15
+ def serial_noun
16
+ @serial_noun ||= RandomWord.nouns.next
17
+ end
18
+
19
+ end
20
+ end
21
+
22
+ begin
23
+ require 'machinist/lathe'
24
+ Machinist::Lathe.send(:include, RandomWord::Machinist)
25
+ rescue LoadError, NameError
26
+ # Machinist is not available
27
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path("../spec_helper", File.dirname(__FILE__))
2
+ require 'machinist/machinable'
3
+ require 'machinist/blueprint'
4
+ require 'machinist/lathe'
5
+ require 'random_word/machinist'
6
+
7
+ describe RandomWord::Machinist do
8
+ let(:klass){ Class.new(Struct.new(:name)) do
9
+ extend Machinist::Machinable
10
+ end
11
+ }
12
+
13
+ it "allows the use of #sw in blue prints" do
14
+ klass.blueprint do
15
+ name do
16
+ serial_word
17
+ end
18
+ end
19
+ klass.make.name.should_not be_nil
20
+ end
21
+
22
+ end
metadata CHANGED
@@ -1,85 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: random-word
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
4
5
  prerelease:
5
- version: 1.0.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Peter Williams
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-23 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2011-07-01 00:00:00.000000000 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2157914840 !ruby/object:Gem::Requirement
18
18
  none: false
19
- requirements:
19
+ requirements:
20
20
  - - ~>
21
- - !ruby/object:Gem::Version
21
+ - !ruby/object:Gem::Version
22
22
  version: 2.3.0
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *2157914840
26
+ - !ruby/object:Gem::Dependency
27
27
  name: yard
28
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirement: &2157914360 !ruby/object:Gem::Requirement
29
29
  none: false
30
- requirements:
30
+ requirements:
31
31
  - - ~>
32
- - !ruby/object:Gem::Version
32
+ - !ruby/object:Gem::Version
33
33
  version: 0.6.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *2157914360
37
+ - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirement: &2157913880 !ruby/object:Gem::Requirement
40
40
  none: false
41
- requirements:
41
+ requirements:
42
42
  - - ~>
43
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *2157913880
48
+ - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &id004 !ruby/object:Gem::Requirement
50
+ requirement: &2157913400 !ruby/object:Gem::Requirement
51
51
  none: false
52
- requirements:
52
+ requirements:
53
53
  - - ~>
54
- - !ruby/object:Gem::Version
54
+ - !ruby/object:Gem::Version
55
55
  version: 1.6.2
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *2157913400
59
+ - !ruby/object:Gem::Dependency
60
60
  name: rcov
61
- requirement: &id005 !ruby/object:Gem::Requirement
61
+ requirement: &2157912920 !ruby/object:Gem::Requirement
62
62
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *id005
70
- description: A random word generator intended for use in test data factories. This library uses a large list (the wordnet corpus) of english words and provides an enumerator interface to that corpus that will return the words in a random order without repeats.
69
+ version_requirements: *2157912920
70
+ - !ruby/object:Gem::Dependency
71
+ name: machinist
72
+ requirement: &2157912440 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0.beta2
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2157912440
81
+ - !ruby/object:Gem::Dependency
82
+ name: activesupport
83
+ requirement: &2157911960 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *2157911960
92
+ - !ruby/object:Gem::Dependency
93
+ name: i18n
94
+ requirement: &2157911480 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: *2157911480
103
+ description: A random word generator intended for use in test data factories. This
104
+ library uses a large list (the wordnet corpus) of english words and provides an
105
+ enumerator interface to that corpus that will return the words in a random order
106
+ without repeats.
71
107
  email: pezra@barelyenough.org
72
108
  executables: []
73
-
74
109
  extensions: []
75
-
76
- extra_rdoc_files:
110
+ extra_rdoc_files:
77
111
  - LICENSE.txt
78
112
  - README.markdown
79
- files:
113
+ files:
80
114
  - .document
81
115
  - .rspec
82
116
  - Gemfile
117
+ - HISTORY.markdown
83
118
  - LICENSE.txt
84
119
  - README.markdown
85
120
  - Rakefile
@@ -88,39 +123,39 @@ files:
88
123
  - data/nouns.dat
89
124
  - lib/random-word.rb
90
125
  - lib/random_word.rb
126
+ - lib/random_word/machinist.rb
91
127
  - spec/random-word_spec.rb
128
+ - spec/random_word/machinist_spec.rb
92
129
  - spec/random_word_spec.rb
93
130
  - spec/spec_helper.rb
94
131
  - spec/support/matchers.rb
132
+ has_rdoc: true
95
133
  homepage: http://github.com/pezra/random-word
96
- licenses:
134
+ licenses:
97
135
  - MIT
98
136
  post_install_message:
99
137
  rdoc_options: []
100
-
101
- require_paths:
138
+ require_paths:
102
139
  - lib
103
- required_ruby_version: !ruby/object:Gem::Requirement
140
+ required_ruby_version: !ruby/object:Gem::Requirement
104
141
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 2610495265960102185
109
- segments:
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ segments:
110
147
  - 0
111
- version: "0"
112
- required_rubygems_version: !ruby/object:Gem::Requirement
148
+ hash: 3491852981360523473
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
150
  none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: "0"
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
118
155
  requirements: []
119
-
120
156
  rubyforge_project:
121
- rubygems_version: 1.8.5
157
+ rubygems_version: 1.6.2
122
158
  signing_key:
123
159
  specification_version: 3
124
160
  summary: Pick random words for factory data
125
161
  test_files: []
126
-