fake_data 1.0.0 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cdaac93546def3c7d0c48e9c30ed2b003e85b7b
4
- data.tar.gz: 70ca387710795bd8c7c8facdb0471ae446e53e4c
3
+ metadata.gz: 41847a41f8158d6ef36a7db01a2ca9c21b2fbaa2
4
+ data.tar.gz: f68e00914385129db81e356a08d26cd33dfb4a03
5
5
  SHA512:
6
- metadata.gz: 5710d6c44169fa92d868c725ed68f980990a6e897bc9526d8c726a38f7f11d6342e2df2581846a742e3e88f0beed1bc220e80ae5bafa3e04f217d7d4734f1917
7
- data.tar.gz: 9af00b36aea62ddfa43208ede20df3aa6414e6b1701f4c80d65926ab78fe59b160836253776cec04d1655405470848b12d9feb3a4a381cb514b2db29b5b90e09
6
+ metadata.gz: fd21e7bfdb387b808aea3c91a14703fabf9a7c2965d4160fa68f01bd334f59f4b97c106c72f72af6fed51de74a6387a66b8acab386465136edf6f9a61abb7af4
7
+ data.tar.gz: c1c9fce599b40728e9aba33cd99ec8b5fa62d079d1e31e50088f7fe313fe78562acc23802e62b6bc22946dde043f299f37e22808c3892b39f28ae77a075c457f
data/README.md CHANGED
@@ -1,14 +1,10 @@
1
1
  [![Build Status](https://travis-ci.org/schovi/FakeData.png?branch=master)](https://travis-ci.org/schovi/FakeData)
2
-
3
2
  [![Gem Version](https://badge.fury.io/rb/fake_data.png)](http://badge.fury.io/rb/fake_data)
4
-
5
3
  [![Coverage Status](https://coveralls.io/repos/schovi/FakeData/badge.png)](https://coveralls.io/r/schovi/FakeData)
6
4
 
7
5
  # FakeData
8
6
 
9
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fake_data`. To experiment with that code, run `bin/console` for an interactive prompt.
10
-
11
- TODO: Delete this and the text above, and describe your gem
7
+ Fake data generator for simple and complex structures or objects. For data generation it uses [Faker gem](https://github.com/stympy/faker)
12
8
 
13
9
  ## Installation
14
10
 
@@ -20,15 +16,130 @@ gem 'fake_data'
20
16
 
21
17
  And then execute:
22
18
 
23
- $ bundle
19
+ ```
20
+ $ bundle
21
+ ```
24
22
 
25
23
  Or install it yourself as:
26
24
 
27
- $ gem install fake_data
25
+ ```
26
+ $ gem install fake_data
27
+ ```
28
28
 
29
29
  ## Usage
30
30
 
31
- TODO: Write usage instructions here
31
+ With simple schema generates fake data. Supports structure controling like how many items array should have or value presence based on probability. For random data is used (Faker gem)[https://github.com/stympy/faker].
32
+
33
+ ### String
34
+
35
+ All following rows are equivalent.
36
+
37
+ ```ruby
38
+ FakeData.once("Hello, my name is %{Faker::Name.name}")
39
+ => "Hello, my name is Miss Darius Stokes"
40
+ FakeData.once("Hello, my name is %{Name.name}")
41
+ => "Hello, my name is Ms. Santino Gutmann"
42
+ FakeData.once("Hello, my name is %{name.name}")
43
+ => "Hello, my name is Miss Edward Kunde"
44
+ ```
45
+
46
+ ### Array
47
+
48
+ #### Simple array with content
49
+
50
+ ```ruby
51
+ FakeData.once(
52
+ [
53
+ "I live in %{address.city}",
54
+ "My family came from %{address.country}"
55
+ ]
56
+ )
57
+ => ["I live in Winnifredshire", "And my family came from Hungary"]
58
+ ```
59
+
60
+ ### Hash
61
+
62
+ ```ruby
63
+ FakeData.once(
64
+ {
65
+ id: "%{number.number(5)}",
66
+ name: "%{name.name}",
67
+ email: "%{internet.email}"
68
+ }
69
+ )
70
+
71
+ => {"id"=>"70095", "name"=>"Mr. Alverta Gibson", "email"=>"seamus@schambergerswaniawski.name"}
72
+ ```
73
+
74
+ ### Repeating
75
+
76
+ #### Generated Array with given number of items
77
+
78
+ Use hash with only one special control key `"%{repeat(n)}"`
79
+
80
+ ```ruby
81
+ FakeData.once(
82
+ {"%{repeat(2)}" => "I have email %{internet.email}"}
83
+ )
84
+ => ["I have email eryn@bayer.name", "I have email roxane.hoppe@rosenbaum.com"]
85
+ ```
86
+
87
+ #### Generated Array with random number of items
88
+
89
+ From empty Array to Array with N items with `repeat(0..n)`
90
+
91
+ ```ruby
92
+ 3.times do
93
+ p FakeData.once({"%{repeat(0..2)}" => "My favorite beer is: %{beer.name}"})
94
+ end
95
+
96
+ => ["My favorite beer is Pliny The Elder", "My favorite beer is: Brooklyn Black"]
97
+ => ["My favorite beer is: Ten FIDY"]
98
+ => []
99
+ ```
100
+
101
+ #### Generated Array with random number of items and nothing for empty array
102
+
103
+ For empty Array returns `nil` with `repeat(0..n, nil: true)`
104
+
105
+ ```ruby
106
+ FakeData.once({"%{repeat(0..1, nil: true)}" => "My favorite beer is: %{beer.name}"})
107
+ => nil
108
+ ```
109
+
110
+ ### Value presence with probability
111
+
112
+ Use hash with only one special control key `"%{maybe}"` - change is 50%. `maybe(20)` - chance is 20%
113
+
114
+ ```ruby
115
+ 2.times do
116
+ FakeData.once({"%{maybe(20)}" => "I like to watch on movies with %{superhero.name}"})
117
+ end
118
+ => "I like to watch on movies with Giant Thanos Thirteen"
119
+ => nil
120
+ ```
121
+
122
+ ### Complex example
123
+
124
+ ```ruby
125
+ FakeData.once(
126
+ {
127
+ id: "%{number.number(5)}",
128
+ name: "%{name.name}",
129
+ age: 20,
130
+ facebook: "%{internet.url('facebook.com/profile')}",
131
+ friends: {
132
+ "%{maybe(75)}" => {
133
+ "%{repeat(2..20)}" => {
134
+ id: "%{number.number(5)}",
135
+ name: "%{name.name}",
136
+ facebook: "%{internet.url('facebook.com/profile')}",
137
+ }
138
+ }
139
+ }
140
+ }
141
+ )
142
+ ```
32
143
 
33
144
  ## Development
34
145
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "fake-data"
4
+ require "fake_data"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -4,7 +4,7 @@ require "fake_data/method/control"
4
4
  module FakeData
5
5
  class Method
6
6
  # TODO: problem with parsing "test()" => method = test; arguments = ["()"]
7
- METHOD_MATCHER = /((?<klass>[a-z_.:]+)\.)?(?<method>[a-z_=\?]+)\s*(\((?<args1>.+)\)|(?<args2>.+))?\s*/i
7
+ METHOD_MATCHER = /((?<klass>[a-z_.:]+)\.)?(?<method>[a-z0-9_=\?]+)\s*(\((?<args1>.+)\)|(?<args2>.+))?\s*/i
8
8
  LEFT_BRACKET_MATCHER = /^\(/
9
9
  RIGHT_BRACKET_MATCHER = /\)$/
10
10
  # TODO: better argument splitting
@@ -1,8 +1,8 @@
1
1
  module FakeData
2
2
  class Method
3
3
  class Control < FakeData::Method
4
-
5
4
  attr_reader :call_block
5
+
6
6
  class << self
7
7
  def repeat(count, params = {}, &block)
8
8
  if count.is_a?(Range)
@@ -1,3 +1,3 @@
1
1
  module FakeData
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Schovanec
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-12 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  version: '0'
198
198
  requirements: []
199
199
  rubyforge_project:
200
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.6.4
201
201
  signing_key:
202
202
  specification_version: 4
203
203
  summary: Universal random data generator