weighted_random 0.1.0 → 0.1.1

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.
data/README.rdoc CHANGED
@@ -26,17 +26,15 @@ Load weighted randomization stuff into desired model and set accessibillity of p
26
26
  class YourModel < ActiveRecord::Base
27
27
  weighted_randomizable
28
28
  attr_accessible :weight, :cumulative_weight
29
- ...
30
29
  end
31
30
 
32
31
  == Usage
33
32
 
34
33
  === Importing data
35
34
 
36
- To import data for randomization you have to provide an array of hashes with <code>weight</code> attributes to
37
- <code>create_with_cumulative_weight</code> method, for example:
35
+ Just create records, each must contain <code>weight</code> value:
38
36
 
39
- FirstName.create_with_cumulative_weight([
37
+ FirstName.create [
40
38
  {:name => "Smith", :weight => 10},
41
39
  {:name => "Johnson", :weight => 8},
42
40
  {:name => "Williams", :weight => 7},
@@ -45,9 +43,27 @@ To import data for randomization you have to provide an array of hashes with <co
45
43
  {:name => "Davis", :weight => 5},
46
44
  {:name => "Miller", :weight => 4},
47
45
  {:name => "Wilson", :weight => 3}
48
- ])
46
+ ]
49
47
 
50
- This method will save all this hashes in database with additional <code>cumulative_weight</code> attribute.
48
+ It automatically sets <code>cumulative_weight</code> attribute for each record.
49
+
50
+ Here is an example of importing data from CSV file:
51
+
52
+ db/seeds/last_names.csv:
53
+ name,weight
54
+ Smith,10
55
+ Johnson,8
56
+ Williams,7
57
+ Jones,6
58
+ Brown,6
59
+ Davis,5
60
+ Miller,4
61
+ Wilson,3
62
+
63
+ db/seeds.rb:
64
+ LastName.create(
65
+ CSV.table(File.expand_path("seeds/last_names.csv", File.dirname(__FILE__))).collect(&:to_hash)
66
+ )
51
67
 
52
68
  === Weighted randomization
53
69
 
@@ -69,26 +85,6 @@ Demonstration:
69
85
  Miller
70
86
  Jones
71
87
 
72
- == Import data from CSV
73
-
74
- Here is an example of importing last names and their frequencies from CSV file:
75
-
76
- db/seeds/last_names.csv:
77
- name,weight
78
- Smith,10
79
- Johnson,8
80
- Williams,7
81
- Jones,6
82
- Brown,6
83
- Davis,5
84
- Miller,4
85
- Wilson,3
86
-
87
- db/seeds.rb:
88
- LastName.create_with_cumulative_weight(
89
- CSV.table(File.expand_path("seeds/last_names.csv", File.dirname(__FILE__))).collect(&:to_hash)
90
- )
91
-
92
88
  == Author
93
89
 
94
90
  Szymon Przybył (http://github.com/apocalyptiq)
@@ -1,3 +1,3 @@
1
1
  module WeightedRandom
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weighted_random
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &83711230 !ruby/object:Gem::Requirement
17
+ requirement: &71386280 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *83711230
25
+ version_requirements: *71386280
26
26
  description: ActiveRecord extension for weighted randomization which supplies loading
27
27
  records with weight for randomize into database and weighted randomization of them
28
28
  email: