wz2008 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea60e8e282623ac141ca48295a3b04842770322c
4
+ data.tar.gz: 9b1d6fdfd390f4ab680e1c6566a6d3b479d98acd
5
+ SHA512:
6
+ metadata.gz: 177796386901c0ee3e77beae97033dd247365a0305000390dc502eab3072873bd61b960ec053df94ef3234c56bfd4619ff8fdc3176027777ad45c0d847bbe9d6
7
+ data.tar.gz: daee46529dbbbc2862bc90f3d665b318fee423758425e4e8efb31ca2dc32cbcd721a41b637874ea4296ad4675edf0a441ddeff52bc360583f99f3001da8381f0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Stefan Wienert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Wz2008'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ require 'rails/dummy/tasks'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,23 @@
1
+ require 'ancestry'
2
+ module Wz2008
3
+ class Category < ActiveRecord::Base
4
+ has_ancestry :cache_depth => true
5
+ scope :isic, -> { where('isic is not null')}
6
+
7
+ def wz_code_list
8
+ wz_code.split('.')
9
+ end
10
+
11
+ before_create do
12
+
13
+ self.hierarchy = case wz_code
14
+ when /^[A-Z]+$/ then 'Section'
15
+ when /^\d+$/ then 'Division'
16
+ when /^\d+\.\d$/ then 'Group'
17
+ when /^\d+\.\d\d$/ then 'Class'
18
+ when /^\d+\.\d\d\.\d$/ then 'Sub-Class'
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Wz2008
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Wz2008
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ require 'pry'
2
+ class Wz2008::Import
3
+ IMPORT = File.join(File.dirname(File.expand_path(__FILE__)), '../../data/original.tsv')
4
+ ENGLISH = File.join(File.dirname(File.expand_path(__FILE__)), '../../data/english.tsv')
5
+
6
+ def self.run
7
+ puts 'Deleting categories....'
8
+ Wz2008::Category.delete_all
9
+ puts 'Importing categories....'
10
+ create_categories
11
+ puts 'Set tree structure...'
12
+ set_tree
13
+ puts "Importing English..."
14
+ import_english
15
+ puts "Finished with #{Wz2008::Category.count} categories"
16
+ end
17
+
18
+ def self.import_english
19
+ headlines = [:lfdnr, :wzcode, :bezeichnung, :isic]
20
+ couples = File.read(ENGLISH).lines.map{|l|
21
+ t = l.split("\t")
22
+ Hash[headlines.zip(t)]
23
+ }
24
+ couples.each do |item|
25
+ Wz2008::Category.find(item[:lfdnr]).update_attributes(description_en: item[:bezeichnung])
26
+ end
27
+ end
28
+
29
+ def self.set_tree
30
+ Wz2008::Category.where('ancestry is not null').find_each do |c|
31
+ parent_code = nil
32
+ case c.wz_code
33
+ when /^(\d+\.\d+)\.\d+$/ then parent_code = $1
34
+ when /^(\d+\.\d)\d$/ then parent_code = $1
35
+ when /^(\d+)\.\d$/ then parent_code = $1
36
+ end
37
+
38
+ if parent_code
39
+ c.parent = Wz2008::Category.where(wz_code: parent_code).first
40
+ # puts "#{c.wz_code} -> #{c.parent.wz_code}"
41
+ c.save
42
+ end
43
+ end
44
+ end
45
+
46
+ def self.create_categories
47
+ headlines = [:lfdnr, :wzcode, :bezeichnung, :isic]
48
+ couples = File.read(IMPORT).lines.map{|l|
49
+ t = l.split("\t")
50
+ Hash[headlines.zip(t)]
51
+ }
52
+ current_category = nil
53
+ couples.each do |item|
54
+ c = Wz2008::Category.new
55
+ c.id = item[:lfdnr]
56
+ c.wz_code = item[:wzcode]
57
+ c.description_de = item[:bezeichnung]
58
+ c.isic = item[:isic].strip if item[:isic].present?
59
+ if item[:wzcode][/^[A-Z]+$/]
60
+ current_category = c
61
+ else
62
+ c.parent = current_category
63
+ end
64
+ c.save
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Wz2008
2
+ VERSION = "0.0.1"
3
+ end
data/lib/wz2008.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "wz2008/engine"
2
+
3
+ module Wz2008
4
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wz2008
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stefan Wienert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ancestry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: sqlite3
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails-dummy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: 'WZ2008 industrial classification codes as ActiveRecord tree '
84
+ email:
85
+ - stefan.wienert@pludoni.de
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - Rakefile
92
+ - app/models/wz2008/category.rb
93
+ - lib/wz2008.rb
94
+ - lib/wz2008/engine.rb
95
+ - lib/wz2008/import.rb
96
+ - lib/wz2008/version.rb
97
+ homepage: https://github.com/pludoni/wz2008
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.2.2
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: WZ2008 industrial classification codes as ActiveRecord tree
121
+ test_files: []