jpx_industry_code 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 258f653213d324a9dcf65ca12aa837a8ea4c30cffb716488e903b30a64623aab
4
- data.tar.gz: '05708e797014fa0af3b78e1ff9581937021b42fa7b2e460e6f7162b9790786aa'
3
+ metadata.gz: 04b18b13e739d6ea4a95dd3cb33f93bde63b499d4767aec7a0e80e17869f542a
4
+ data.tar.gz: c3080bc4f9708503250b0aed379f36e72df356b5f6330be63d249b1b96736c09
5
5
  SHA512:
6
- metadata.gz: b50f092449c019362e34d1d1324730d3d4dad37272b0326add8267c724c0eb6b010059bc74511ba6a61ef5e3e55e54f7eb370d3520d1403f576f33c486189729
7
- data.tar.gz: 137422c85b6efbdff550f6cc6b1f1546e116f02249085ac646b75a57fbe2b5d312f43e2fb6f0f0b923f0ac0a01fd6b12a319a6e7871cde562a1311b03792b6aa
6
+ metadata.gz: 9842219e4dac4af698baa6c75ec9bc4c5f1f69b19ae290dfdc8dc429b517662b92e5af63f58cc7d0d538464e44dff9bf970c401d13168a43cba0d0492925f4f3
7
+ data.tar.gz: 14e6f41fec2e269d637427d7a3d9726cc111120b56340b775cabdba8856912a60fd330d9e823e48db9575e3dc7b058f5b655f8443946f71dc21de0967bdae85f
@@ -9,14 +9,39 @@ class JpxIndustryCode
9
9
  { id: 2, name: '鉱業' },
10
10
  { id: 3, name: '建設業' },
11
11
  { id: 4, name: '製造業' },
12
- { id: 5, name: '電気・ガス業' },
12
+ { id: 5, name: '電気・ガス業' },
13
13
  { id: 6, name: '運輸・情報通信業' },
14
14
  { id: 7, name: '商業' },
15
15
  { id: 8, name: '金融・保険業' },
16
16
  { id: 9, name: '不動産業' },
17
- { id: 10, name: 'サービス業' }
17
+ { id: 10, name: 'サービス業' }
18
18
  ]
19
19
  end
20
+
21
+ def find_by!(find_option)
22
+ validate_find_option!(find_option)
23
+
24
+ all.find(raise_not_found) do |jpx_industry_code_category|
25
+ jpx_industry_code_category[find_option.flatten[0]] == find_option.flatten[1]
26
+ end
27
+ end
28
+
29
+ def find_by(find_option)
30
+ all.find do |jpx_industry_code_category|
31
+ jpx_industry_code_category[find_option.flatten[0]] == find_option.flatten[1]
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def validate_find_option!(find_option)
38
+ raise JpxIndustryCode::Errors::InvalidArgumentError, ':id or :name must be specified.' if !find_option.is_a?(Hash) || (find_option[:id].nil? && find_option[:name].nil?)
39
+ raise JpxIndustryCode::Errors::InvalidArgumentError, 'Single keyword argument can be specified.' if find_option.keys.length > 1
40
+ end
41
+
42
+ def raise_not_found
43
+ proc { raise JpxIndustryCode::Errors::NotFoundError }
44
+ end
20
45
  end
21
46
  end
22
47
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class JpxIndustryCode
4
+ class Errors
5
+ class JpxIndustryCodeError < StandardError; end
6
+ class InvalidArgumentError < JpxIndustryCodeError; end
7
+ class NotFoundError < JpxIndustryCodeError; end
8
+ end
9
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jpx_industry_code/category'
4
+ require 'jpx_industry_code/errors'
4
5
 
5
6
  class JpxIndustryCode
6
7
  class << self
@@ -11,12 +12,12 @@ class JpxIndustryCode
11
12
  { id: 3, jpx_industry_code_category_id: 3, name: '建設業', code: '2050' },
12
13
  { id: 4, jpx_industry_code_category_id: 4, name: '食料品', code: '3050' },
13
14
  { id: 5, jpx_industry_code_category_id: 4, name: '繊維製品', code: '3100' },
14
- { id: 6, jpx_industry_code_category_id: 4, name: 'パルプ・紙', code: '3150' },
15
+ { id: 6, jpx_industry_code_category_id: 4, name: 'パルプ・紙', code: '3150' },
15
16
  { id: 7, jpx_industry_code_category_id: 4, name: '化学', code: '3200' },
16
17
  { id: 8, jpx_industry_code_category_id: 4, name: '医薬品', code: '3250' },
17
18
  { id: 9, jpx_industry_code_category_id: 4, name: '石油・石炭製品', code: '3300' },
18
- { id: 10, jpx_industry_code_category_id: 4, name: 'ゴム製品', code: '3350' },
19
- { id: 11, jpx_industry_code_category_id: 4, name: 'ガラス・土石製品', code: '3400' },
19
+ { id: 10, jpx_industry_code_category_id: 4, name: 'ゴム製品', code: '3350' },
20
+ { id: 11, jpx_industry_code_category_id: 4, name: 'ガラス・土石製品', code: '3400' },
20
21
  { id: 12, jpx_industry_code_category_id: 4, name: '鉄鋼', code: '3450' },
21
22
  { id: 13, jpx_industry_code_category_id: 4, name: '非鉄金属', code: '3500' },
22
23
  { id: 14, jpx_industry_code_category_id: 4, name: '金属製品', code: '3550' },
@@ -38,8 +39,33 @@ class JpxIndustryCode
38
39
  { id: 30, jpx_industry_code_category_id: 8, name: '保険業', code: '7150' },
39
40
  { id: 31, jpx_industry_code_category_id: 8, name: 'その他金融業', code: '7200' },
40
41
  { id: 32, jpx_industry_code_category_id: 9, name: '不動産業', code: '8050' },
41
- { id: 33, jpx_industry_code_category_id: 10, name: 'サービス業', code: '9050' }
42
+ { id: 33, jpx_industry_code_category_id: 10, name: 'サービス業', code: '9050' }
42
43
  ]
43
44
  end
45
+
46
+ def find_by!(find_option)
47
+ validate_find_option!(find_option)
48
+
49
+ all.find(raise_not_found) do |jpx_industry_code|
50
+ jpx_industry_code[find_option.flatten[0]] == find_option.flatten[1]
51
+ end
52
+ end
53
+
54
+ def find_by(find_option)
55
+ all.find do |jpx_industry_code|
56
+ jpx_industry_code[find_option.flatten[0]] == find_option.flatten[1]
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def validate_find_option!(find_option)
63
+ raise JpxIndustryCode::Errors::InvalidArgumentError, ':id, :name or :code must be specified.' if !find_option.is_a?(Hash) || (find_option[:id].nil? && find_option[:name].nil? && find_option[:code].nil?)
64
+ raise JpxIndustryCode::Errors::InvalidArgumentError, 'Single keyword argument can be specified.' if find_option.keys.length > 1
65
+ end
66
+
67
+ def raise_not_found
68
+ proc { raise JpxIndustryCode::Errors::NotFoundError }
69
+ end
44
70
  end
45
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpx_industry_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rui Onodera
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/jpx_industry_code.rb
20
20
  - lib/jpx_industry_code/category.rb
21
+ - lib/jpx_industry_code/errors.rb
21
22
  homepage: https://github.com/ai-capital/jpx_industry_code
22
23
  licenses:
23
24
  - MIT