random_text 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/random_text.rb +14 -0
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rubygems/specification'
4
4
  require 'date'
5
5
 
6
6
  GEM = "random_text"
7
- GEM_VERSION = "0.0.1"
7
+ GEM_VERSION = "0.0.2"
8
8
  AUTHOR = "toy"
9
9
  EMAIL = "ivan@workisfun.ru"
10
10
  HOMEPAGE = ""
data/lib/random_text.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'activesupport'
3
3
 
4
+ $KCODE = "u"
5
+
4
6
  class RandomText
5
7
  class Randomized
6
8
  def initialize(data)
@@ -11,6 +13,10 @@ class RandomText
11
13
  @list << s
12
14
  s
13
15
  end
16
+ def unique(n)
17
+ raise "Dictionary has only #{@list.length} elements (you asked for n)" if n > @list.length
18
+ @list.sort{ rand - 0.5 }.slice(0, n)
19
+ end
14
20
  end
15
21
 
16
22
  def initialize(*args)
@@ -22,6 +28,14 @@ class RandomText
22
28
  def word
23
29
  @words.get
24
30
  end
31
+
32
+ def words(n)
33
+ Array.new(n){ word }.join(' ').capitalize
34
+ end
35
+
36
+ def unique_words(n)
37
+ @words.unique(n)
38
+ end
25
39
 
26
40
  def sentence
27
41
  @sentences.get
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random_text
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - toy
@@ -9,7 +9,7 @@ autorequire: random_text
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-31 00:00:00 +04:00
12
+ date: 2008-09-02 00:00:00 +04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15