odca 0.2.1 → 0.2.2
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 +5 -5
- data/Gemfile.lock +1 -1
- data/config/overlays_info.yml +2 -2
- data/lib/odca.rb +3 -10
- data/lib/odca/headful_overlay.rb +1 -1
- data/lib/odca/overlays/{encode_overlay.rb → character_encoding_overlay.rb} +3 -3
- data/lib/odca/overlays/label_overlay.rb +75 -37
- data/lib/odca/parser.rb +1 -1
- data/lib/odca/schema_parser.rb +0 -10
- data/lib/odca/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3922731ee0fae6d9b57651cd56aa6c05fc43712e
|
4
|
+
data.tar.gz: 8a7e49f4bb9cd958ea951c19c21b9c46a6d85198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03bf0e1a11647358fa36c01bd3f1b7820ded612c02a334ab2316d58bab4d6955439b1de36ad07951593e2fb4687663788f869e04d15bddea70086cacd3724041
|
7
|
+
data.tar.gz: 50a458ba35f70823e83d1d1501811e3c848b4cdeb1cf7de0753d5e6ba7d6cf11fe96770e8d95c34029fcd237c1a7dcb517bb1468716cbc495b0c57ccb1b03cb6
|
data/Gemfile.lock
CHANGED
data/config/overlays_info.yml
CHANGED
data/lib/odca.rb
CHANGED
@@ -3,16 +3,9 @@ require 'odca/parser'
|
|
3
3
|
require 'odca/schema_base'
|
4
4
|
require 'odca/headful_overlay'
|
5
5
|
require 'odca/parentful_overlay'
|
6
|
-
|
7
|
-
require
|
8
|
-
|
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'
|
15
|
-
require 'odca/overlays/mapping_overlay'
|
6
|
+
Dir[File.expand_path('../odca/overlays/*.rb', __FILE__)].each do |file|
|
7
|
+
require file
|
8
|
+
end
|
16
9
|
|
17
10
|
module Odca
|
18
11
|
ROOT_PATH = File.expand_path('..', File.dirname(__FILE__))
|
data/lib/odca/headful_overlay.rb
CHANGED
@@ -44,7 +44,7 @@ module Odca
|
|
44
44
|
|
45
45
|
def overlay_info
|
46
46
|
overlay_class_name = overlay.class.name.split('::').last
|
47
|
-
overlay_key = overlay_class_name.gsub('Overlay', '').downcase
|
47
|
+
overlay_key = overlay_class_name.gsub('Overlay', '').gsub(/([^\^])([A-Z])/,'\1_\2').downcase
|
48
48
|
overlays_info.fetch(overlay_key) do
|
49
49
|
raise "Not found specific information about #{overlay_class_name}"
|
50
50
|
end
|
@@ -3,15 +3,15 @@ require 'odca/null_value'
|
|
3
3
|
|
4
4
|
module Odca
|
5
5
|
module Overlays
|
6
|
-
class
|
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
|
-
|
14
|
-
|
13
|
+
default_character_encoding: DEFAULT_ENCODING,
|
14
|
+
attr_character_encoding: attr_values
|
15
15
|
}
|
16
16
|
end
|
17
17
|
end
|
@@ -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
|
-
|
19
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
81
|
+
self
|
82
|
+
end
|
52
83
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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, :
|
107
|
+
attr_reader :attr_name, :categories, :label
|
63
108
|
|
64
|
-
def initialize(attr_name:,
|
109
|
+
def initialize(attr_name:, categories:, label:)
|
65
110
|
@attr_name = attr_name
|
66
|
-
@
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
136
|
+
categories: categories,
|
99
137
|
label: label
|
100
138
|
}
|
101
139
|
end
|
data/lib/odca/parser.rb
CHANGED
@@ -72,7 +72,7 @@ module Odca
|
|
72
72
|
def save_overlay(headful_overlay, path:)
|
73
73
|
overlay_class_name = headful_overlay.overlay.class
|
74
74
|
.name.split('::').last
|
75
|
-
hl =
|
75
|
+
hl = HashlinkGenerator.call(headful_overlay)
|
76
76
|
|
77
77
|
File.open("#{path}/#{overlay_class_name}-#{hl}.json", 'w') do |f|
|
78
78
|
f.write(JSON.pretty_generate(headful_overlay))
|
data/lib/odca/schema_parser.rb
CHANGED
@@ -19,19 +19,9 @@ module Odca
|
|
19
19
|
overlay_attrs = {}
|
20
20
|
overlay_indexes = overlay_dtos.map(&:index)
|
21
21
|
|
22
|
-
entry_overlay_indexes = overlay_dtos.select do |ov|
|
23
|
-
ov.name == 'Entry Overlay'
|
24
|
-
end.map(&:index)
|
25
|
-
|
26
22
|
records.each do |row|
|
27
23
|
attr_name = row[3]
|
28
24
|
attr_type = row[4]
|
29
|
-
entry_overlay_indexes.each do |ov_index|
|
30
|
-
if row[ov_index]
|
31
|
-
attr_type = 'Array[Text]'
|
32
|
-
break
|
33
|
-
end
|
34
|
-
end
|
35
25
|
|
36
26
|
schema_base.add_attribute(
|
37
27
|
SchemaBase::Attribute.new(
|
data/lib/odca/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mitwicki
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: base58
|
@@ -75,8 +75,8 @@ files:
|
|
75
75
|
- lib/odca/headful_overlay.rb
|
76
76
|
- lib/odca/null_value.rb
|
77
77
|
- lib/odca/overlay.rb
|
78
|
+
- lib/odca/overlays/character_encoding_overlay.rb
|
78
79
|
- lib/odca/overlays/conditional_overlay.rb
|
79
|
-
- lib/odca/overlays/encode_overlay.rb
|
80
80
|
- lib/odca/overlays/entry_overlay.rb
|
81
81
|
- lib/odca/overlays/format_overlay.rb
|
82
82
|
- lib/odca/overlays/header.rb
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.6.8
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Overlays Data Capture Architecture (ODCA) objects parser
|