odca 0.1.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 562f570cb79b02ab96b7a11c6f420618cd3c492c
4
- data.tar.gz: 2ada1a4608bbe3ebc638a48a7930e1c400822833
3
+ metadata.gz: 2ee133fe221ff06912b00edf86e317ba229e7154
4
+ data.tar.gz: fc77a7f7a79bc1b914e14838110ca8b0487111a8
5
5
  SHA512:
6
- metadata.gz: 650781f9962b095d9453df16e1a308e56106efbc9bba6161f7024c3ece4e43433be408defe70e74968cbbb035ad2a3971bf179b469740e6cc8fc28d74f9357d8
7
- data.tar.gz: fb3b5e88c8c20294e8c2b702edab6030027694f05123dd1294d0f06eb675ee8b5c4d250830709be5d468eb3ad2d6c20557faf3bd660b6728b1e4cc787697f6f8
6
+ metadata.gz: 34e413488e8df0de267d2f3a962c57d0576ee1c24bd5ebb27705220bcff6f9b53bbe4569445dc97b82e8e2b6a496003cc0af9d60cbaf5b6ec7ff26d4536e8716
7
+ data.tar.gz: 3dae720cd4c23a489cbaec68436df826297c459a39d469b5714c89c0da869cc6b20bb4844703acd1c26908c9de64764e070ed8c44d2cf3fe3244f7e5e4f46335
data/.gitignore CHANGED
@@ -43,7 +43,7 @@ build-iPhoneSimulator/
43
43
 
44
44
  # for a library or gem, you might want to ignore these files since the code is
45
45
  # intended to run in multiple environments; otherwise, check them in:
46
- # Gemfile.lock
46
+ Gemfile.lock
47
47
  # .ruby-version
48
48
  # .ruby-gemset
49
49
 
@@ -1,35 +1,29 @@
1
1
  label:
2
2
  type_v1: spec/overlay/label/1.0
3
- description: Category and attribute labels for %{schema_name}
4
3
 
5
4
  format:
6
5
  type_v1: spec/overlay/format/1.0
7
- description: Attribute formats for %{schema_name}
8
6
 
9
- encode:
10
- type_v1: spec/overlay/encode/1.0
11
- description: Character set encoding for %{schema_name}
7
+ character_encoding:
8
+ type_v1: spec/overlay/character_encoding/1.0
12
9
 
13
10
  entry:
14
11
  type_v1: spec/overlay/entry/1.0
15
- description: Field entries for %{schema_name}
16
12
 
17
13
  information:
18
14
  type_v1: spec/overlay/information/1.0
19
- description: Informational items for %{schema_name}
20
15
 
21
16
  conditional:
22
17
  type_v1: spec/overlay/conditional/1.0
23
- description:
24
18
 
25
19
  source:
26
20
  type_v1: spec/overlay/source/1.0
27
- description: Source endpoints for %{schema_name}
28
21
 
29
22
  review:
30
23
  type_v1: spec/overlay/review/1.0
31
- description: Field entry review comments for %{schema_name}
32
24
 
33
25
  masking:
34
26
  type_v1: spec/overlay/masking/1.0
35
- description: Masking attributes for %{schema_name}
27
+
28
+ mapping:
29
+ type_v1: spec/overlay/mapping/1.0
data/lib/odca.rb CHANGED
@@ -3,15 +3,9 @@ require 'odca/parser'
3
3
  require 'odca/schema_base'
4
4
  require 'odca/headful_overlay'
5
5
  require 'odca/parentful_overlay'
6
- require 'odca/overlays/format_overlay'
7
- require 'odca/overlays/label_overlay'
8
- require 'odca/overlays/encode_overlay'
9
- require 'odca/overlays/entry_overlay'
10
- require 'odca/overlays/information_overlay'
11
- require 'odca/overlays/conditional_overlay'
12
- require 'odca/overlays/source_overlay'
13
- require 'odca/overlays/review_overlay'
14
- require 'odca/overlays/masking_overlay'
6
+ Dir[File.expand_path('../odca/overlays/*.rb', __FILE__)].each do |file|
7
+ require file
8
+ end
15
9
 
16
10
  module Odca
17
11
  ROOT_PATH = File.expand_path('..', File.dirname(__FILE__))
@@ -1,15 +1,10 @@
1
- require 'digest/sha2'
2
- require 'base58'
1
+ require 'hashlink'
3
2
  require 'json'
4
3
 
5
4
  module Odca
6
5
  class HashlinkGenerator
7
6
  def self.call(schema)
8
- Base58.encode(
9
- Digest::SHA2.hexdigest(
10
- JSON.pretty_generate(schema)
11
- ).to_i(16)
12
- )
7
+ Hashlink.encode(data: JSON.generate(schema)).split(':')[1]
13
8
  end
14
9
  end
15
10
  end
@@ -32,11 +32,7 @@ module Odca
32
32
  Odca::Overlays::Header.new(
33
33
  role: role,
34
34
  purpose: purpose,
35
- type: overlay_info['type_v1'],
36
- description: format(
37
- overlay_info['description'],
38
- schema_name: parentful_overlay.parent.name
39
- )
35
+ type: overlay_info['type_v1']
40
36
  )
41
37
  end
42
38
 
@@ -48,7 +44,7 @@ module Odca
48
44
 
49
45
  def overlay_info
50
46
  overlay_class_name = overlay.class.name.split('::').last
51
- overlay_key = overlay_class_name.gsub('Overlay', '').downcase
47
+ overlay_key = overlay_class_name.gsub('Overlay', '').gsub(/([^\^])([A-Z])/,'\1_\2').downcase
52
48
  overlays_info.fetch(overlay_key) do
53
49
  raise "Not found specific information about #{overlay_class_name}"
54
50
  end
@@ -3,15 +3,15 @@ require 'odca/null_value'
3
3
 
4
4
  module Odca
5
5
  module Overlays
6
- class EncodeOverlay
6
+ class CharacterEncodingOverlay
7
7
  extend Overlay
8
8
 
9
9
  DEFAULT_ENCODING = 'utf-8'.freeze
10
10
 
11
11
  def to_h
12
12
  {
13
- default_encoding: DEFAULT_ENCODING,
14
- attr_encoding: attr_values
13
+ default_character_encoding: DEFAULT_ENCODING,
14
+ attr_character_encoding: attr_values
15
15
  }
16
16
  end
17
17
  end
@@ -1,13 +1,12 @@
1
1
  module Odca
2
2
  module Overlays
3
3
  class Header
4
- attr_reader :issued_by, :role, :purpose, :description, :type
4
+ attr_reader :issued_by, :role, :purpose, :type
5
5
 
6
- def initialize(role:, purpose:, description:, type:, issued_by: '')
6
+ def initialize(role:, purpose:, type:, issued_by: '')
7
7
  @issued_by = issued_by
8
8
  @role = role
9
9
  @purpose = purpose
10
- @description = description
11
10
  @type = type
12
11
  end
13
12
 
@@ -15,7 +14,6 @@ module Odca
15
14
  {
16
15
  '@context' => 'https://odca.tech/overlays/v1',
17
16
  type: type,
18
- description: description,
19
17
  issued_by: issued_by,
20
18
  role: role || '',
21
19
  purpose: purpose || ''
@@ -3,20 +3,22 @@ require 'odca/null_value'
3
3
  module Odca
4
4
  module Overlays
5
5
  class LabelOverlay
6
- attr_reader :attributes, :language
6
+ attr_reader :attributes, :language, :category_resolver
7
7
 
8
- def initialize(language:)
8
+ def initialize(language:, category_resolver: CategoryResolver.new)
9
9
  @attributes = []
10
10
  @language = language
11
+ @category_resolver = category_resolver
11
12
  end
12
13
 
13
14
  def to_h
15
+ resolved_categories = category_resolver.call(attributes)
14
16
  {
15
17
  language: language,
16
18
  attr_labels: attr_labels,
17
- attr_categories: attr_categories,
18
- category_labels: category_labels,
19
- category_attributes: category_attributes
19
+ attr_categories: resolved_categories.attr_categories,
20
+ cat_labels: resolved_categories.category_labels,
21
+ cat_attributes: resolved_categories.category_attributes
20
22
  }
21
23
  end
22
24
 
@@ -35,35 +37,78 @@ module Odca
35
37
  end
36
38
  end
37
39
 
38
- private def attr_categories
39
- attributes.map(&:category).uniq.map do |cat|
40
- next if cat.empty?
41
- cat.downcase.gsub(/\s+/, '_').to_sym
42
- end.compact
43
- end
40
+ class CategoryResolver
41
+ attr_reader :attr_categories, :category_labels, :category_attributes
42
+
43
+ def initialize
44
+ @attr_categories = []
45
+ @category_labels = {}
46
+ @category_attributes = {}
47
+ end
44
48
 
45
- private def category_labels
46
- attributes.map(&:category).uniq
47
- .each_with_object({}) do |cat, memo|
48
- next if cat.empty?
49
- memo[cat.downcase.gsub(/\s+/, '_').to_sym] = cat
49
+ def call(attributes)
50
+ attributes.each do |attribute|
51
+ next if attribute.categories.empty?
52
+ categories = attribute.categories.dup
53
+ category = categories.pop
54
+
55
+ supercategory_numbers = []
56
+
57
+ categories.each do |supercategory|
58
+ supercategory_attr = find_or_create_category_attr(
59
+ supercategory_numbers, supercategory
60
+ )
61
+ supercategory_numbers.push(
62
+ supercategory_attr.delete('_').split('-').last
63
+ )
64
+ unless attr_categories.include? supercategory_attr
65
+ attr_categories.push(supercategory_attr)
66
+ end
67
+ category_labels[supercategory_attr] = supercategory
68
+ end
69
+
70
+ category_attr = find_or_create_category_attr(
71
+ supercategory_numbers, category
72
+ )
73
+ unless attr_categories.include? category_attr
74
+ attr_categories.push(category_attr)
75
+ end
76
+ category_labels[category_attr] = category
77
+
78
+ category_attributes[category_attr] = category_attributes
79
+ .fetch(category_attr) { [] }.push(attribute.attr_name).uniq
50
80
  end
51
- end
81
+ self
82
+ end
52
83
 
53
- private def category_attributes
54
- attributes.each_with_object({}) do |attr, memo|
55
- next if attr.category.empty?
56
- category_attr = attr.category.downcase.gsub(/\s+/, '_').to_sym
57
- (memo[category_attr] ||= []) << attr.attr_name
84
+ private def find_or_create_category_attr(supercategory_numbers, category)
85
+ nested_category_numbers =
86
+ if supercategory_numbers.empty?
87
+ '-'
88
+ else
89
+ "-#{supercategory_numbers.join('-')}-"
90
+ end
91
+ category_attr = category_labels.select do |key, value|
92
+ value == category &&
93
+ key.match("_cat#{nested_category_numbers}[0-9]*_")
94
+ end
95
+ if !category_attr.empty?
96
+ category_attr.keys.first
97
+ else
98
+ subcategory_number = category_labels.select do |key, _v|
99
+ key.match("_cat#{nested_category_numbers}[0-9]*_")
100
+ end.size + 1
101
+ "_cat#{nested_category_numbers}#{subcategory_number}_"
102
+ end
58
103
  end
59
104
  end
60
105
 
61
106
  class LabelAttribute
62
- attr_reader :attr_name, :category, :label
107
+ attr_reader :attr_name, :categories, :label
63
108
 
64
- def initialize(attr_name:, category:, label:)
109
+ def initialize(attr_name:, categories:, label:)
65
110
  @attr_name = attr_name
66
- @category = category
111
+ @categories = categories
67
112
  @label = label
68
113
  end
69
114
  end
@@ -81,21 +126,14 @@ module Odca
81
126
  end
82
127
 
83
128
  def call
84
- category = Odca::NullValue.new
85
- label = Odca::NullValue.new
86
-
87
- splited = value.split('|')
88
- case splited.length
89
- when 1
90
- label = value.strip
91
- when 2
92
- category = splited[0].strip
93
- label = splited[1].strip
94
- end
129
+ splited = value.split('|').map(&:strip)
130
+
131
+ label = splited.empty? ? Odca::NullValue.new : splited.pop
132
+ categories = splited
95
133
 
96
134
  {
97
135
  attr_name: attr_name.strip,
98
- category: category,
136
+ categories: categories,
99
137
  label: label
100
138
  }
101
139
  end
@@ -0,0 +1,15 @@
1
+ require 'odca/overlay'
2
+
3
+ module Odca
4
+ module Overlays
5
+ class MappingOverlay
6
+ extend Overlay
7
+
8
+ def to_h
9
+ {
10
+ attr_mapping: attr_values
11
+ }
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/odca/parser.rb CHANGED
@@ -31,6 +31,7 @@ module Odca
31
31
  schemas = separate_schemas(records)
32
32
  schemas.each do |schema|
33
33
  schema_base, overlays = schema.call
34
+ next unless schema_base && overlays
34
35
  save(schema_base: schema_base, overlays: overlays)
35
36
  end
36
37
  end
@@ -72,7 +73,7 @@ module Odca
72
73
  def save_overlay(headful_overlay, path:)
73
74
  overlay_class_name = headful_overlay.overlay.class
74
75
  .name.split('::').last
75
- hl = 'hl:' + HashlinkGenerator.call(headful_overlay)
76
+ hl = HashlinkGenerator.call(headful_overlay)
76
77
 
77
78
  File.open("#{path}/#{overlay_class_name}-#{hl}.json", 'w') do |f|
78
79
  f.write(JSON.pretty_generate(headful_overlay))
@@ -8,6 +8,7 @@ module Odca
8
8
  end
9
9
 
10
10
  def call
11
+ return unless records.first[0]
11
12
  schema_base = Odca::SchemaBase.new(
12
13
  Odca::SchemaBase::Header.new(
13
14
  name: records.first[0],
@@ -21,10 +22,14 @@ module Odca
21
22
 
22
23
  records.each do |row|
23
24
  attr_name = row[3]
25
+ attr_type = row[4]
26
+
27
+ next unless attr_name && attr_type
28
+
24
29
  schema_base.add_attribute(
25
30
  SchemaBase::Attribute.new(
26
31
  name: attr_name,
27
- type: row[4],
32
+ type: attr_type,
28
33
  pii: row[5]
29
34
  )
30
35
  )
data/lib/odca/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Odca
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
data/odca.gemspec CHANGED
@@ -5,11 +5,11 @@ require 'odca/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'odca'
7
7
  spec.version = Odca::VERSION
8
- spec.authors = ['THCLab']
9
- spec.email = ['olichwiruk@gmail.pl']
8
+ spec.authors = ["Robert Mitwicki", "Marcin Olichwiruk", "Michał Pietrus"]
9
+ spec.email = ['robert@thclab.online']
10
10
 
11
- spec.summary = 'ODCA implementation in ruby'
12
- spec.homepage = 'https://github.com/THCLab/odca-ruby'
11
+ spec.summary = 'Overlays Data Capture Architecture (ODCA) objects parser'
12
+ spec.homepage = 'https://odca.online'
13
13
  spec.license = 'MIT'
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ['lib']
27
27
 
28
- spec.add_dependency 'base58', '~> 0.2'
28
+ spec.add_dependency 'hashlink', '~> 0.0.1'
29
29
 
30
30
  spec.add_development_dependency 'rake', '~> 13.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
metadata CHANGED
@@ -1,29 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
- - THCLab
7
+ - Robert Mitwicki
8
+ - Marcin Olichwiruk
9
+ - Michał Pietrus
8
10
  autorequire:
9
11
  bindir: exe
10
12
  cert_chain: []
11
- date: 2019-11-18 00:00:00.000000000 Z
13
+ date: 2021-06-15 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
- name: base58
16
+ name: hashlink
15
17
  requirement: !ruby/object:Gem::Requirement
16
18
  requirements:
17
19
  - - "~>"
18
20
  - !ruby/object:Gem::Version
19
- version: '0.2'
21
+ version: 0.0.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - "~>"
25
27
  - !ruby/object:Gem::Version
26
- version: '0.2'
28
+ version: 0.0.1
27
29
  - !ruby/object:Gem::Dependency
28
30
  name: rake
29
31
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +56,7 @@ dependencies:
54
56
  version: '3.0'
55
57
  description:
56
58
  email:
57
- - olichwiruk@gmail.pl
59
+ - robert@thclab.online
58
60
  executables: []
59
61
  extensions: []
60
62
  extra_rdoc_files: []
@@ -63,7 +65,6 @@ files:
63
65
  - ".rspec"
64
66
  - ".travis.yml"
65
67
  - Gemfile
66
- - Gemfile.lock
67
68
  - LICENSE
68
69
  - README.md
69
70
  - Rakefile
@@ -73,13 +74,14 @@ files:
73
74
  - lib/odca/headful_overlay.rb
74
75
  - lib/odca/null_value.rb
75
76
  - lib/odca/overlay.rb
77
+ - lib/odca/overlays/character_encoding_overlay.rb
76
78
  - lib/odca/overlays/conditional_overlay.rb
77
- - lib/odca/overlays/encode_overlay.rb
78
79
  - lib/odca/overlays/entry_overlay.rb
79
80
  - lib/odca/overlays/format_overlay.rb
80
81
  - lib/odca/overlays/header.rb
81
82
  - lib/odca/overlays/information_overlay.rb
82
83
  - lib/odca/overlays/label_overlay.rb
84
+ - lib/odca/overlays/mapping_overlay.rb
83
85
  - lib/odca/overlays/masking_overlay.rb
84
86
  - lib/odca/overlays/review_overlay.rb
85
87
  - lib/odca/overlays/source_overlay.rb
@@ -89,7 +91,7 @@ files:
89
91
  - lib/odca/schema_parser.rb
90
92
  - lib/odca/version.rb
91
93
  - odca.gemspec
92
- homepage: https://github.com/THCLab/odca-ruby
94
+ homepage: https://odca.online
93
95
  licenses:
94
96
  - MIT
95
97
  metadata: {}
@@ -112,5 +114,5 @@ rubyforge_project:
112
114
  rubygems_version: 2.6.8
113
115
  signing_key:
114
116
  specification_version: 4
115
- summary: ODCA implementation in ruby
117
+ summary: Overlays Data Capture Architecture (ODCA) objects parser
116
118
  test_files: []
data/Gemfile.lock DELETED
@@ -1,36 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- odca (0.1.2)
5
- base58 (~> 0.2)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- base58 (0.2.3)
11
- diff-lcs (1.3)
12
- rake (13.0.0)
13
- rspec (3.9.0)
14
- rspec-core (~> 3.9.0)
15
- rspec-expectations (~> 3.9.0)
16
- rspec-mocks (~> 3.9.0)
17
- rspec-core (3.9.0)
18
- rspec-support (~> 3.9.0)
19
- rspec-expectations (3.9.0)
20
- diff-lcs (>= 1.2.0, < 2.0)
21
- rspec-support (~> 3.9.0)
22
- rspec-mocks (3.9.0)
23
- diff-lcs (>= 1.2.0, < 2.0)
24
- rspec-support (~> 3.9.0)
25
- rspec-support (3.9.0)
26
-
27
- PLATFORMS
28
- ruby
29
-
30
- DEPENDENCIES
31
- odca!
32
- rake (~> 13.0)
33
- rspec (~> 3.0)
34
-
35
- BUNDLED WITH
36
- 1.16.2