data_maker 2.0.1 → 2.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.
@@ -0,0 +1,36 @@
1
+ module DataMaker
2
+ module Validators
3
+ class ChineseCharacters
4
+
5
+ CJK_CHARACTER_RANGES = [ { min: "4E00", max: "9FFF", comment: "Common" },
6
+ { min: "3400", max: "4DFF", comment: "Rare" },
7
+ { min: "20000", max: "2A6DF", comment: "Rare, historic" },
8
+ { min: "F900", max: "FAFF", comment: "Duplicates, unifiable variants" },
9
+ { min: "2F800", max: "2FA1F", comment: "unifiable variants" },
10
+ { min: "AC00", max: "D7AF", comment: "Hangul syllables" } ]
11
+
12
+ def initialize(characters)
13
+ @characters = characters
14
+ end
15
+
16
+ def valid?
17
+ valid_characters = true
18
+ @characters.each_char do |character|
19
+ hex_chinese = "%04x" % character[0].ord
20
+ valid_characters = true unless within_cjk_range(hex_chinese)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def within_cjk_range(hex_string)
27
+ val = hex_string.hex
28
+ CJK_CHARACTER_RANGES.each do |valid_range|
29
+ return true if val >= valid_range[:min].hex && val <= valid_range[:max].hex
30
+ end
31
+
32
+ return false
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/data_maker.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module DataMaker
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.1"
3
3
 
4
4
  require 'data_maker/utilities/array_utilities'
5
5
  require 'data_maker/utilities/module_utilities'
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe DataMaker::China::Name do
4
+ describe "#self.first_name" do
5
+ it "generates a valid chinese first name" do
6
+ first_name = described_class.first_name
7
+ validate = DataMaker::Validators::ChineseCharacters.new(first_name)
8
+ expect(validate.valid?).to be_truthy
9
+ end
10
+
11
+ context "when number_of_characters is less than 1" do
12
+ it "raises an error" do
13
+ expect { described_class.first_name(rand(0..-3)) }.to raise_error
14
+ end
15
+
16
+ context "or number_of_characters is greater than 2" do
17
+ it "raises an error" do
18
+ expect { described_class.first_name(rand(3..5)) }.to raise_error
19
+ end
20
+ end
21
+ end
22
+
23
+ context "when number_of_characters is set to 1" do
24
+ it "returns one character" do
25
+ first_name = described_class.first_name(1)
26
+ expect(first_name.length).to eq(1)
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "#self.last_name" do
32
+ it "generates a valid chinese last name" do
33
+ first_name = described_class.first_name
34
+ validate = DataMaker::Validators::ChineseCharacters.new(first_name)
35
+ expect(validate.valid?).to be_truthy
36
+ end
37
+ end
38
+
39
+ describe "#self.full_name" do
40
+ it "generates a valid full chinese name" do
41
+ full_name = described_class.full_name
42
+ validate = DataMaker::Validators::ChineseCharacters.new(full_name)
43
+ expect(validate.valid?).to be_truthy
44
+ end
45
+
46
+ context "when eastern_format is true" do
47
+ it "reverses the order of the full_name" do
48
+ expect { described_class.full_name(true, rand(0..-3)) }.to raise_error
49
+ end
50
+
51
+ context "or eastern_format is false" do
52
+ it "does reverses the order of the full_name" do
53
+ described_class.full_name(true)
54
+ end
55
+ end
56
+ end
57
+
58
+ context "when first_name_character_count is less than 1" do
59
+ it "raises an error" do
60
+ expect { described_class.full_name(true, rand(0..-3)) }.to raise_error
61
+ end
62
+
63
+ context "or first_name_character_count is greater than 2" do
64
+ it "raises an error" do
65
+ expect { described_class.full_name(true, rand(3..5)) }.to raise_error
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -1,11 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe DataMaker::China::PhoneNumber do
4
- let(:phone_number) { described_class }
5
-
6
4
  describe "#self.mobile" do
7
5
  it "generates a valid mobile number" do
8
- number = phone_number.mobile
6
+ number = described_class.mobile
9
7
  validate = DataMaker::Validators::ChinesePhoneNumber.new(number)
10
8
  expect(validate.valid?).to be_truthy
11
9
  end
@@ -5,7 +5,7 @@ RSpec.describe DataMaker do
5
5
 
6
6
  describe "#VERSION" do
7
7
  # For each iteration of a version this would always get changed.
8
- let(:current_version) { "2.0.1" }
8
+ let(:current_version) { "2.1.1" }
9
9
 
10
10
  it { expect(described_class).to be_const_defined(:VERSION) }
11
11
  it { expect(described_class::VERSION).to eq(current_version) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kareem Gan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2015-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simplecov
@@ -185,12 +185,17 @@ files:
185
185
  - Rakefile
186
186
  - data_maker.gemspec
187
187
  - lib/data_maker.rb
188
+ - lib/data_maker/china/name.rb
188
189
  - lib/data_maker/china/phone_number.rb
190
+ - lib/data_maker/data/china/name/first_names
191
+ - lib/data_maker/data/china/name/last_names
189
192
  - lib/data_maker/data/china/phone_number/landline_phone_prefixes
190
193
  - lib/data_maker/data/china/phone_number/mobile_phone_prefixes
191
194
  - lib/data_maker/utilities/array_utilities.rb
192
195
  - lib/data_maker/utilities/module_utilities.rb
196
+ - lib/data_maker/validators/chinese_characters.rb
193
197
  - lib/data_maker/validators/chinese_phone_number.rb
198
+ - spec/lib/data_maker/china/name_spec.rb
194
199
  - spec/lib/data_maker/china/phone_number_spec.rb
195
200
  - spec/lib/data_maker/data_maker_spec.rb
196
201
  - spec/lib/data_maker/support/matchers/phone_number_matcher.rb
@@ -222,6 +227,7 @@ signing_key:
222
227
  specification_version: 4
223
228
  summary: Data generator gem for aiding in development and testing for applications.
224
229
  test_files:
230
+ - spec/lib/data_maker/china/name_spec.rb
225
231
  - spec/lib/data_maker/china/phone_number_spec.rb
226
232
  - spec/lib/data_maker/data_maker_spec.rb
227
233
  - spec/lib/data_maker/support/matchers/phone_number_matcher.rb