isic 0.0.1 → 0.9.0

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.
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "awesome_print"
23
24
  end
@@ -1,5 +1,4 @@
1
1
  require "isic/version"
2
-
3
- module Isic
4
- # Your code goes here...
5
- end
2
+ require "isic/isic"
3
+ require "isic/entity"
4
+ require "isic/search"
@@ -0,0 +1,36 @@
1
+ module Isic
2
+ class Entity
3
+
4
+ def initialize(code)
5
+ @code = code
6
+ end
7
+
8
+ def classify(options = {})
9
+ translation = options[:translation] || :en
10
+ all_codes.inject({}) do |hash, (key, value)|
11
+ hash[key] = Isic::Search.new(value, translation: translation).first
12
+ hash
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def all_codes
19
+ case @code
20
+ when /\d{4}/
21
+ {class: @code, group: @code[0..2], division: @code[0..1], section: section(@code[0..1])}
22
+ when /\d{3}/
23
+ [group: @code, division: @code[0..1], section: section(@code[0..1])]
24
+ when /\d{2}/
25
+ [division: @code, section: section(@code)]
26
+ when /[A-Z]/
27
+ [section: @code]
28
+ end
29
+ end
30
+
31
+ def section(division)
32
+ Isic::DIVISIONS.select { |k,v| v.include?(division) }.keys.first
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,65 @@
1
+ module Isic
2
+
3
+ DIVISIONS = {}
4
+ DIVISIONS['A'] = %w( 01 02 03 )
5
+ DIVISIONS['B'] = %w( 05 06 07 08 09 )
6
+ DIVISIONS['C'] = %w( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 )
7
+ DIVISIONS['D'] = %w( 35 )
8
+ DIVISIONS['E'] = %w( 36 37 38 39 )
9
+ DIVISIONS['F'] = %w( 41 42 43 )
10
+ DIVISIONS['G'] = %w( 45 46 47 )
11
+ DIVISIONS['H'] = %w( 49 50 51 52 53 )
12
+ DIVISIONS['I'] = %w( 55 56 )
13
+ DIVISIONS['J'] = %w( 58 59 60 61 62 63 )
14
+ DIVISIONS['K'] = %w( 64 65 66 )
15
+ DIVISIONS['L'] = %w( 68 )
16
+ DIVISIONS['M'] = %w( 69 70 71 72 73 74 75 )
17
+ DIVISIONS['N'] = %w( 77 78 79 80 81 82 )
18
+ DIVISIONS['O'] = %w( 84 )
19
+ DIVISIONS['P'] = %w( 85 )
20
+ DIVISIONS['Q'] = %w( 86 87 88 )
21
+ DIVISIONS['R'] = %w( 90 91 92 93 )
22
+ DIVISIONS['S'] = %w( 94 95 96 )
23
+ DIVISIONS['T'] = %w( 97 98 )
24
+ DIVISIONS['U'] = %w( 99 )
25
+
26
+ class << self
27
+
28
+ def sections(options = {})
29
+ translation = options[:translation] || :en
30
+ Search.new('[A-Z]', translation: translation).all
31
+ end
32
+
33
+ def divisions(options = {})
34
+ translation = options[:translation] || :en
35
+ if options[:section] && DIVISIONS.keys.include?(options[:section])
36
+ code = DIVISIONS[options[:section]].join('|')
37
+ Search.new(code, translation: translation).all
38
+ else
39
+ []
40
+ end
41
+ end
42
+
43
+ def groups(options = {})
44
+ translation = options[:translation] || :en
45
+ if options[:division] && /\d{2}/.match(options[:division])
46
+ code = "#{options[:division]}\\d"
47
+ Search.new(code, translation: translation).all
48
+ else
49
+ []
50
+ end
51
+ end
52
+
53
+ def classes(options = {})
54
+ translation = options[:translation] || :en
55
+ if options[:group] && /\d{3}/.match(options[:group])
56
+ code = "#{options[:group]}\\d"
57
+ Search.new(code, translation: translation).all
58
+ else
59
+ []
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,36 @@
1
+ module Isic
2
+ class Search
3
+
4
+ FILES = {
5
+ en: 'files/ISIC_Rev_4_english_structure.txt',
6
+ es: 'files/ISIC_Rev_4_spanish_structure.txt',
7
+ fr: 'files/ISIC_Rev_4_french_structure.txt'
8
+ }
9
+
10
+ ENCODINGS = {
11
+ en: 'utf-8',
12
+ es: 'iso-8859-15:utf-8',
13
+ fr: 'iso-8859-15:utf-8'
14
+ }
15
+
16
+ def initialize(regexp, translation: :en)
17
+ @regexp = regexp
18
+ @file = FILES[translation]
19
+ @encoding = ENCODINGS[translation]
20
+ end
21
+
22
+ def all
23
+ entities = []
24
+ File.open(@file, encoding: @encoding).each do |line|
25
+ md = /"(#{@regexp})","(.+)"/.match(line)
26
+ entities << {code: md[1], description: md[2]} if md
27
+ end
28
+ entities
29
+ end
30
+
31
+ def first
32
+ all.first
33
+ end
34
+
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Isic
2
- VERSION = "0.0.1"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Vidal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-13 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: International Standard Industrial Classification
42
56
  email:
43
57
  - javier@javiervidal.net
@@ -50,8 +64,14 @@ files:
50
64
  - LICENSE.txt
51
65
  - README.md
52
66
  - Rakefile
67
+ - files/ISIC_Rev_4_english_structure.txt
68
+ - files/ISIC_Rev_4_french_structure.txt
69
+ - files/ISIC_Rev_4_spanish_structure.txt
53
70
  - isic.gemspec
54
71
  - lib/isic.rb
72
+ - lib/isic/entity.rb
73
+ - lib/isic/isic.rb
74
+ - lib/isic/search.rb
55
75
  - lib/isic/version.rb
56
76
  homepage: https://github.com/javiervidal/isic
57
77
  licenses: