randwordjp 0.0.17 → 0.0.18
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 +4 -4
- data/.gitignore +1 -0
- data/lib/randwordjp/version.rb +1 -1
- data/lib/randwordjp.rb +19 -15
- data/spec/randwordjp_spec.rb +14 -0
- metadata +2 -2
- data/lib/.randwordjp.rb.swp +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21846a80524f373da48f1f782cc8feb4f6640156
|
4
|
+
data.tar.gz: 2a7afccbc037ceaa5c3569c017dbc9657186209c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f3e95880b8589c18cb0ac884e17a0b3d91860d19715b359c7c8954821cddb6f1dcf59ab97f848d69c76016e938b2df9b6d7204c58292472852fc4a820958792
|
7
|
+
data.tar.gz: a4c30d8f48cfe8cd76ac6ebbb8dbe1255269066b0830442a68f970336e83d6a4ddd372adae7f75f312a4f5f79a49fe6a8d76931973f3454495549de61bd3323d
|
data/.gitignore
CHANGED
data/lib/randwordjp/version.rb
CHANGED
data/lib/randwordjp.rb
CHANGED
@@ -45,11 +45,12 @@ module Randwordjp
|
|
45
45
|
|
46
46
|
# 全角カタカナの文字列を取得する。
|
47
47
|
# @param [Integer] length 文字列長
|
48
|
-
# @param [Boolean]
|
48
|
+
# @param [Boolean] opts オプション設定
|
49
|
+
# @option opts [Boolean] :old 旧仮名文字の利用の可否
|
49
50
|
# @return [String] lengthで指定した文字列長の文字列
|
50
|
-
def self.zenkaku_katakana(length = 10,
|
51
|
+
def self.zenkaku_katakana(length = 10, opts = { old: false })
|
51
52
|
words = []
|
52
|
-
if
|
53
|
+
if opts[:old]
|
53
54
|
base = ('ア'..'ン').to_a
|
54
55
|
else
|
55
56
|
base = ('ア'..'ン').to_a.join.gsub(/ヰヱ/, '').split(//)
|
@@ -62,11 +63,12 @@ module Randwordjp
|
|
62
63
|
|
63
64
|
# 全角ひらがなの文字列を取得する。
|
64
65
|
# @param [Integer] length 文字列長
|
65
|
-
# @param [Boolean]
|
66
|
+
# @param [Boolean] opts オプション設定
|
67
|
+
# @option opts [Boolean] :old 旧仮名文字の利用の可否
|
66
68
|
# @return [String] lengthで指定した文字列長の文字列
|
67
|
-
def self.zenkaku_hirakana(length = 10,
|
69
|
+
def self.zenkaku_hirakana(length = 10, opts = { old: false })
|
68
70
|
words = []
|
69
|
-
if
|
71
|
+
if opts[:old]
|
70
72
|
base = ('あ'..'ん').to_a
|
71
73
|
else
|
72
74
|
base = ('あ'..'ん').to_a.join.gsub(/ゐゑ/, '').split(//)
|
@@ -118,7 +120,7 @@ module Randwordjp
|
|
118
120
|
# メールアドレス風の文字列を取得する。
|
119
121
|
# @param [String] randword トップレベルドメインの文字列を指定する。
|
120
122
|
# @param [Integer] local_length ローカルパートの文字列長
|
121
|
-
# @param [Integer]
|
123
|
+
# @param [Integer] domain_length ドメインパートの文字列長
|
122
124
|
# @return [String] lengthで指定した文字列長の文字列
|
123
125
|
def self.mail_address(randword = 'rand', local_length = 10, domain_length = 10)
|
124
126
|
local_part = alphanumeric_plus(rand(local_length) + 1)
|
@@ -129,7 +131,7 @@ module Randwordjp
|
|
129
131
|
# Date型の日付を取得する。
|
130
132
|
# @param [Date] date 指定日
|
131
133
|
# @param [Integer] before 指定日より後の最大何日までを対象とする
|
132
|
-
# @param [Integer]
|
134
|
+
# @param [Integer] after 指定日より前の最大何日までを対象とする
|
133
135
|
# @return [Date] 日付を取得する
|
134
136
|
def self.date(date = Date.today, before = 100, after = 100)
|
135
137
|
(date + (rand(after)) - (rand(before))).to_s
|
@@ -159,15 +161,16 @@ module Randwordjp
|
|
159
161
|
|
160
162
|
# Hash型の名前データを取得する
|
161
163
|
# genderは男性はMで女性はFになります。
|
162
|
-
# @param [
|
164
|
+
# @param [Hash] opts オプション設定
|
165
|
+
# @option opts [Hash] :only :male 男性のみの出力 :female 女性のみの出力
|
163
166
|
# @return [Hash] :kanji => 漢字名, :kana => 読み仮名, :gender => 性別
|
164
|
-
def self.namae(
|
167
|
+
def self.namae(opts = {only: false } )
|
165
168
|
table = 'namaelist'
|
166
169
|
Sequel.connect(@db_connect) do |db|
|
167
170
|
data = db.from(table)
|
168
|
-
if
|
171
|
+
if opts[:only] == :male
|
169
172
|
data = data.where(gender: 1)
|
170
|
-
elsif
|
173
|
+
elsif opts[:only] == :female
|
171
174
|
data = data.where(gender: 2)
|
172
175
|
end
|
173
176
|
no = Random.rand(data.count)
|
@@ -182,9 +185,10 @@ module Randwordjp
|
|
182
185
|
end
|
183
186
|
|
184
187
|
# 日本の郵便番号を取得します
|
185
|
-
# @param [
|
188
|
+
# @param [Hash] opts オプション設定
|
189
|
+
# @option opts [Boolean] :hyphen true ハイフンありで出力 false ハイフン無しで出力
|
186
190
|
# @return [String] 郵便番号
|
187
|
-
def self.zip(
|
191
|
+
def self.zip(opts = {hyphen: false } )
|
188
192
|
table = 'ziplist'
|
189
193
|
Sequel.connect(@db_connect) do |db|
|
190
194
|
data = db.from(table)
|
@@ -192,7 +196,7 @@ module Randwordjp
|
|
192
196
|
data = data.select(:zip)
|
193
197
|
@zip_data = (data.limit(1).offset(no).first)[:zip]
|
194
198
|
end
|
195
|
-
if
|
199
|
+
if opts[:hyphen]
|
196
200
|
return @zip_data[0,3] + "-" + @zip_data[3,4]
|
197
201
|
end
|
198
202
|
return @zip_data
|
data/spec/randwordjp_spec.rb
CHANGED
@@ -117,4 +117,18 @@ describe Randwordjp do
|
|
117
117
|
expect(Randwordjp.myoji.to_s).not_to eq(Randwordjp.myoji.to_s)
|
118
118
|
end
|
119
119
|
end
|
120
|
+
|
121
|
+
describe 'zip code' do
|
122
|
+
it 'zip is should have numeric which is length 7 ' do
|
123
|
+
expect(Randwordjp.zip).to match(/[0-9]{7}/)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'zip is should have numeric which is [0-9]{3}-[0-9]{4} , when hyphen is true' do
|
127
|
+
expect(Randwordjp.zip(hyphen: true)).to match(/[0-9]{3}-[0-9]{4}/)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'zip is not should have next time' do
|
131
|
+
expect(Randwordjp.zip).not_to eq(Randwordjp.zip)
|
132
|
+
end
|
133
|
+
end
|
120
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: randwordjp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- inpwjp
|
@@ -82,7 +82,6 @@ files:
|
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
|
-
- lib/.randwordjp.rb.swp
|
86
85
|
- lib/randwordjp.db
|
87
86
|
- lib/randwordjp.rb
|
88
87
|
- lib/randwordjp.yml
|
@@ -117,3 +116,4 @@ summary: get Japanese random words.
|
|
117
116
|
test_files:
|
118
117
|
- spec/randwordjp_spec.rb
|
119
118
|
- spec/spec_helper.rb
|
119
|
+
has_rdoc:
|
data/lib/.randwordjp.rb.swp
DELETED
Binary file
|