randexp-multibyte 0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/characterlists/kanji +2136 -0
- data/lib/randexp-multibyte.rb +1 -0
- data/lib/randexp/multibyte.rb +12 -0
- data/lib/randexp/multibyte/characterlists.rb +2 -0
- data/lib/randexp/multibyte/characterlists/kanji.rb +14 -0
- data/lib/randexp/multibyte/core_ext.rb +3 -0
- data/lib/randexp/multibyte/core_ext/randgen.rb +23 -0
- data/lib/randexp/multibyte/core_ext/reducer.rb +47 -0
- data/lib/randexp/multibyte/version.rb +5 -0
- data/randexp-multibyte.gemspec +25 -0
- metadata +101 -0
@@ -0,0 +1 @@
|
|
1
|
+
require "randexp/multibyte"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "randexp"
|
2
|
+
|
3
|
+
dir = File.expand_path("multibyte", File.dirname(__FILE__))
|
4
|
+
require dir + "/version"
|
5
|
+
require dir + "/core_ext"
|
6
|
+
require dir + "/characterlists"
|
7
|
+
|
8
|
+
class Randexp
|
9
|
+
class Multibyte
|
10
|
+
RANDEXP_MULTIBYTE_ROOT = File.expand_path("../../", File.dirname(__FILE__))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class RealCharacter
|
2
|
+
def self.load_kanji
|
3
|
+
characterlist_file = File.expand_path("characterlists/kanji", ::Randexp::Multibyte::RANDEXP_MULTIBYTE_ROOT)
|
4
|
+
if File.exists?(characterlist_file)
|
5
|
+
File.read(characterlist_file).split
|
6
|
+
else
|
7
|
+
raise "words file not found"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.kanji
|
12
|
+
@@kanji ||= load_kanji
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Randgen
|
2
|
+
def self.hiragana(options = {})
|
3
|
+
length = options[:length] || 1
|
4
|
+
length.of { ('ぁ'..'ん').to_a.pick }.join
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.katakana(options = {})
|
8
|
+
length = options[:length] || 1
|
9
|
+
length.of { ('ァ'..'ヴ').to_a.pick }.join
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.kanji(options = {})
|
13
|
+
length = options[:length] || 1
|
14
|
+
length.of { RealCharacter.kanji.to_a.pick }.join
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.japanese(options = {})
|
18
|
+
length = options[:length] || 1
|
19
|
+
length.of {
|
20
|
+
[ hiragana, katakana, kanji ].pick
|
21
|
+
}.join
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Randexp
|
2
|
+
class Reducer
|
3
|
+
def self.hiragana(quantity)
|
4
|
+
case quantity
|
5
|
+
when :'?' then ['', Randgen.hiragana].pick
|
6
|
+
when :+, :'+?' then Randgen.hiragana(:length => (1..5).to_a.sample)
|
7
|
+
when :*, :'*?' then ['', Randgen.hiragana(:length => (1..5).to_a.sample)].pick
|
8
|
+
when Range then Randgen.hiragana(:length => quantity.pick)
|
9
|
+
when 1, nil then Randgen.hiragana
|
10
|
+
when Integer then Randgen.hiragana(:length => quantity)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.katakana(quantity)
|
15
|
+
case quantity
|
16
|
+
when :'?' then ['', Randgen.katakana].pick
|
17
|
+
when :+, :'+?' then Randgen.katakana(:length => (1..5).to_a.sample)
|
18
|
+
when :*, :'*?' then ['', Randgen.katakana(:length => (1..5).to_a.sample)].pick
|
19
|
+
when Range then Randgen.katakana(:length => quantity.pick)
|
20
|
+
when 1, nil then Randgen.katakana
|
21
|
+
when Integer then Randgen.katakana(:length => quantity)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.kanji(quantity)
|
26
|
+
case quantity
|
27
|
+
when :'?' then ['', Randgen.kanji].pick
|
28
|
+
when :+, :'+?' then Randgen.kanji(:length => (1..5).to_a.sample)
|
29
|
+
when :*, :'*?' then ['', Randgen.kanji(:length => (1..5).to_a.sample)].pick
|
30
|
+
when Range then Randgen.kanji(:length => quantity.pick)
|
31
|
+
when 1, nil then Randgen.kanji
|
32
|
+
when Integer then Randgen.kanji(:length => quantity)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.japanese(quantity)
|
37
|
+
case quantity
|
38
|
+
when :'?' then ['', Randgen.japanese].pick
|
39
|
+
when :+, :'+?' then Randgen.japanese(:length => (1..5).to_a.sample)
|
40
|
+
when :*, :'*?' then ['', Randgen.japanese(:length => (1..5).to_a.sample)].pick
|
41
|
+
when Range then Randgen.japanese(:length => quantity.pick)
|
42
|
+
when 1, nil then Randgen.japanese
|
43
|
+
when Integer then Randgen.japanese(:length => quantity)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'randexp/multibyte/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "randexp-multibyte"
|
8
|
+
spec.version = Randexp::Multibyte::VERSION
|
9
|
+
spec.authors = ["Naoki Shimizu"]
|
10
|
+
spec.email = ["hcs0035@gmail.com"]
|
11
|
+
spec.summary = %q{randexp extension for multibyte characters}
|
12
|
+
spec.description = %q{randexp extension for multibyte characters}
|
13
|
+
spec.homepage = "https://github.com/deme0607/randexp-multibyte"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "randexp"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: randexp-multibyte
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Naoki Shimizu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: randexp
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: randexp extension for multibyte characters
|
56
|
+
email:
|
57
|
+
- hcs0035@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- characterlists/kanji
|
68
|
+
- lib/randexp-multibyte.rb
|
69
|
+
- lib/randexp/multibyte.rb
|
70
|
+
- lib/randexp/multibyte/characterlists.rb
|
71
|
+
- lib/randexp/multibyte/characterlists/kanji.rb
|
72
|
+
- lib/randexp/multibyte/core_ext.rb
|
73
|
+
- lib/randexp/multibyte/core_ext/randgen.rb
|
74
|
+
- lib/randexp/multibyte/core_ext/reducer.rb
|
75
|
+
- lib/randexp/multibyte/version.rb
|
76
|
+
- randexp-multibyte.gemspec
|
77
|
+
homepage: https://github.com/deme0607/randexp-multibyte
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.2.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: randexp extension for multibyte characters
|
101
|
+
test_files: []
|