vydumschik 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/data/addresses.yml +5048 -0
- data/data/names.yml +8585 -0
- data/lib/vydumschik/address.rb +59 -0
- data/lib/vydumschik/lorem.rb +90 -0
- data/lib/vydumschik/name.rb +45 -0
- data/lib/vydumschik/version.rb +3 -0
- data/lib/vydumschik.rb +7 -0
- data/vydumschik.gemspec +21 -0
- metadata +79 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Vydumschik
|
4
|
+
|
5
|
+
# This module generates random addresses
|
6
|
+
module Address
|
7
|
+
|
8
|
+
# Maximum number of apartments in building
|
9
|
+
MAX_APT = 100
|
10
|
+
|
11
|
+
# Maximum number of buildings for different types of streets
|
12
|
+
BUILDING_LIMITS = {:street => 50, :alley => 10, :avenue => 120, :square => 10, :other => 20}
|
13
|
+
|
14
|
+
# Probability of building without apartments
|
15
|
+
HOUSE_PROBABILITY = 0.2
|
16
|
+
|
17
|
+
# Probability of building number having a modifier
|
18
|
+
MODIFIER_PROBABILITY = 0.05
|
19
|
+
|
20
|
+
# Building number modifiers
|
21
|
+
BUILDING_MODIFIERS = %w(а б в г д)
|
22
|
+
|
23
|
+
# Returns a random street name
|
24
|
+
def self.street
|
25
|
+
data[:streets][rand data[:streets].length][:name]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a random building number
|
29
|
+
def self.building(limit = BUILDING_LIMITS[:other])
|
30
|
+
bld = (1+rand(limit)).to_s
|
31
|
+
bld+='-'+BUILDING_MODIFIERS[rand BUILDING_MODIFIERS.length] if rand<MODIFIER_PROBABILITY
|
32
|
+
bld
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a random apartment number
|
36
|
+
def self.apartment
|
37
|
+
(1+rand(MAX_APT)).to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns a random street address
|
41
|
+
def self.street_address
|
42
|
+
street = data[:streets][rand data[:streets].length]
|
43
|
+
bld = building(BUILDING_LIMITS[street[:type]])
|
44
|
+
if rand>0.5
|
45
|
+
apt = (rand<HOUSE_PROBABILITY) ? bld : bld+'/'+apartment
|
46
|
+
else
|
47
|
+
apt = (rand<HOUSE_PROBABILITY) ? "д. #{bld}" : "д. #{bld}, кв. #{apartment}"
|
48
|
+
end
|
49
|
+
"#{street[:name]}, #{apt}"
|
50
|
+
end
|
51
|
+
|
52
|
+
private_class_method :data
|
53
|
+
|
54
|
+
def self.data
|
55
|
+
@data ||= YAML.load_file(File.expand_path('../../../data/addresses.yml', __FILE__))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
module Vydumschik
|
3
|
+
|
4
|
+
# This module generate lipsum-like russian pseudosentences.
|
5
|
+
#
|
6
|
+
# Warning!
|
7
|
+
# To avoid using ActiveSupport for multibyte support, or anything similar,
|
8
|
+
# I just assume that all russian chars are 2-byte (as in UTF8) and that I
|
9
|
+
# always get a russian char when I ask for one.
|
10
|
+
module Lorem
|
11
|
+
|
12
|
+
# Word length
|
13
|
+
WORD_LIMITS = [2, 10]
|
14
|
+
|
15
|
+
# Sentence length, in words
|
16
|
+
SENTENCE_LIMITS = [5, 10]
|
17
|
+
|
18
|
+
# Paragraph length, in sentences
|
19
|
+
PARA_LIMITS = [5, 10]
|
20
|
+
|
21
|
+
# Russian consonants
|
22
|
+
CONSONANTS = %w(б в г д ж з й к л м н п р с т ф х ц ч ш щ)
|
23
|
+
|
24
|
+
# Russian vowels
|
25
|
+
VOWELS = %w(а е ё и о у ы э ю я)
|
26
|
+
|
27
|
+
# Consonants, normalized by character frequency
|
28
|
+
CONSONANTS_NORMALIZED = %w(б б б б б б б б б б б б б б б б б б б в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в в г г г г г г г г г г г г г г г г г г г д д д д д д д д д д д д д д д д д д д д д д д д д д д д д д д д ж ж ж ж ж ж ж ж ж ж ж ж з з з з з з з з з з з з з з з з з з й й й й й й й й й й й к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к к л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л л м м м м м м м м м м м м м м м м м м м м м м м м м м м м м м м м н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н н п п п п п п п п п п п п п п п п п п п п п п п п п п р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р р с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с с т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т т ф х х х х х х х х ц ц ц ч ч ч ч ч ч ч ч ч ч ч ч ч ч ч ч ч ч ш ш ш ш ш ш ш ш ш щ щ щ)
|
29
|
+
|
30
|
+
# Vowels, normalized by character frequency
|
31
|
+
VOWELS_NORMALIZED = %w(а а а а а а а а а а а а а а а а а а а а а а а а а а а а е е е е е е е е е е е е е е е е е е е е е е е е е е е е е е е и и и и и и и и и и и и и и и и и и и и и и о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о о у у у у у у у у у ы ы ы ы ы ы э ю ю я я я я я я я)
|
32
|
+
|
33
|
+
# Returns a random word. Passing a previous word affects the first character
|
34
|
+
def self.word(previous_word=nil)
|
35
|
+
if previous_word
|
36
|
+
last_char = previous_word[-2,2]
|
37
|
+
if CONSONANTS.include?(last_char)
|
38
|
+
next_char = VOWELS_NORMALIZED
|
39
|
+
else
|
40
|
+
next_char = CONSONANTS_NORMALIZED
|
41
|
+
end
|
42
|
+
else
|
43
|
+
next_char = rand>0.5 ? CONSONANTS_NORMALIZED : VOWELS_NORMALIZED
|
44
|
+
end
|
45
|
+
word = ''
|
46
|
+
random_length(WORD_LIMITS).times do
|
47
|
+
word << next_char[rand next_char.length]
|
48
|
+
next_char = next_char===CONSONANTS_NORMALIZED ? VOWELS_NORMALIZED : CONSONANTS_NORMALIZED
|
49
|
+
end
|
50
|
+
|
51
|
+
word
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns a random sentence
|
55
|
+
def self.sentence
|
56
|
+
last_word = nil
|
57
|
+
sentence = []
|
58
|
+
random_length(SENTENCE_LIMITS).times do
|
59
|
+
sentence << word(last_word)
|
60
|
+
end
|
61
|
+
capitalize_ru(sentence.join(' ')) + '.'
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns a random paragraph
|
65
|
+
def self.paragraph
|
66
|
+
sentences = []
|
67
|
+
random_length(PARA_LIMITS).times do
|
68
|
+
sentences << sentence
|
69
|
+
end
|
70
|
+
sentences.join(' ')
|
71
|
+
end
|
72
|
+
|
73
|
+
private_class_method :random_length, capitalize_ru
|
74
|
+
|
75
|
+
# Random value based on limits
|
76
|
+
def self.random_length(limits)
|
77
|
+
limits.first + rand(limits.last-limits.first+1)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Capitalizes a russian string. Works only with UTF8.
|
81
|
+
def self.capitalize_ru(word)
|
82
|
+
w = word.clone
|
83
|
+
code = (w[1]-0b10000000) + ((w[0]-0b11000000)<<6)
|
84
|
+
code -= 32
|
85
|
+
w[1] = (code & 0b00111111) | 0b10000000
|
86
|
+
w[0] = (code >> 6) | 0b11000000
|
87
|
+
w
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Vydumschik
|
4
|
+
|
5
|
+
# This module generates human names
|
6
|
+
module Name
|
7
|
+
|
8
|
+
# Random first name (gender = :male/:female/nil for random)
|
9
|
+
def self.first_name(gender=nil)
|
10
|
+
gender ||= random_gender
|
11
|
+
gender == :female ? data[:female][rand data[:female].length] : data[:male][rand data[:male].length][:name]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Random middle name (gender = :male/:female/nil for random)
|
15
|
+
def self.middle_name(gender=nil)
|
16
|
+
gender ||= random_gender
|
17
|
+
name = data[:male][rand data[:male].length]
|
18
|
+
gender == :female ? name[:female_middle] : name[:male_middle]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Random surnamename (gender = :male/:female/nil for random)
|
22
|
+
def self.surname(gender=nil)
|
23
|
+
gender ||= random_gender
|
24
|
+
surname = data[:surnames][rand data[:surnames].length]
|
25
|
+
surname += 'а' if gender==:female
|
26
|
+
surname
|
27
|
+
end
|
28
|
+
|
29
|
+
# Random full name - surname, first name and middle name (gender = :male/:female/nil for random)
|
30
|
+
def self.full_name(gender=nil)
|
31
|
+
gender ||= random_gender
|
32
|
+
[surname(gender), first_name(gender), middle_name(gender)].join(' ')
|
33
|
+
end
|
34
|
+
|
35
|
+
private_class_method :data, :random_gender
|
36
|
+
|
37
|
+
def self.data
|
38
|
+
@data ||= YAML.load_file(File.expand_path('../../../data/names.yml', __FILE__))
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.random_gender
|
42
|
+
rand>0.5 ? :female : :male
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/vydumschik.rb
ADDED
data/vydumschik.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "vydumschik/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "vydumschik"
|
7
|
+
s.version = Vydumschik::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Leonid Shevtsov"]
|
10
|
+
s.email = ["leonid@shevtsov.me"]
|
11
|
+
s.homepage = "https://github.com/leonid-shevtsov/vydumschik"
|
12
|
+
s.summary = %q{A fake data library (Vydumschik is russian for "inventor")}
|
13
|
+
s.description = %q{Vydumschik creates fake Cyrillic names, surnames, full names, and lipsum-like text}
|
14
|
+
|
15
|
+
s.rubyforge_project = "vydumschik"
|
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
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vydumschik
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Leonid Shevtsov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-03 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Vydumschik creates fake Cyrillic names, surnames, full names, and lipsum-like text
|
23
|
+
email:
|
24
|
+
- leonid@shevtsov.me
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- data/addresses.yml
|
37
|
+
- data/names.yml
|
38
|
+
- lib/vydumschik.rb
|
39
|
+
- lib/vydumschik/address.rb
|
40
|
+
- lib/vydumschik/lorem.rb
|
41
|
+
- lib/vydumschik/name.rb
|
42
|
+
- lib/vydumschik/version.rb
|
43
|
+
- vydumschik.gemspec
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: https://github.com/leonid-shevtsov/vydumschik
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
requirements: []
|
72
|
+
|
73
|
+
rubyforge_project: vydumschik
|
74
|
+
rubygems_version: 1.6.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: A fake data library (Vydumschik is russian for "inventor")
|
78
|
+
test_files: []
|
79
|
+
|