odca 0.2.1 → 0.2.2

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
- SHA256:
3
- metadata.gz: 306b405a4d5e14907204fed9977e07364b498211a23a1723100d1b3bd204d122
4
- data.tar.gz: b7dac9d14a0c56e8297162dccdddb6c91c4ba1853cadbdd3930961895ae843d3
2
+ SHA1:
3
+ metadata.gz: 3922731ee0fae6d9b57651cd56aa6c05fc43712e
4
+ data.tar.gz: 8a7e49f4bb9cd958ea951c19c21b9c46a6d85198
5
5
  SHA512:
6
- metadata.gz: d9d1c6e96291197e1409a0c9baa7048110d2339a69b4b57130e67ab2dcb101313979b6cee413e0eb631ef61a1e33606317cad52fa92bf5bc6151cb1855e63801
7
- data.tar.gz: 07500e7e0beba5511fa7539eff470349cb3994f8de267ff23b75ccf12e98ea09ac74f850e8fa670217ebcc45fea5e6e5df56ebe7298a2780e9702d5a69428668
6
+ metadata.gz: 03bf0e1a11647358fa36c01bd3f1b7820ded612c02a334ab2316d58bab4d6955439b1de36ad07951593e2fb4687663788f869e04d15bddea70086cacd3724041
7
+ data.tar.gz: 50a458ba35f70823e83d1d1501811e3c848b4cdeb1cf7de0753d5e6ba7d6cf11fe96770e8d95c34029fcd237c1a7dcb517bb1468716cbc495b0c57ccb1b03cb6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- odca (0.2.0)
4
+ odca (0.2.1)
5
5
  base58 (~> 0.2)
6
6
 
7
7
  GEM
@@ -4,8 +4,8 @@ label:
4
4
  format:
5
5
  type_v1: spec/overlay/format/1.0
6
6
 
7
- encode:
8
- type_v1: spec/overlay/encode/1.0
7
+ character_encoding:
8
+ type_v1: spec/overlay/character_encoding/1.0
9
9
 
10
10
  entry:
11
11
  type_v1: spec/overlay/entry/1.0
@@ -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
- 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'
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__))
@@ -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 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
@@ -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
@@ -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 = 'hl:' + HashlinkGenerator.call(headful_overlay)
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))
@@ -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(
@@ -1,3 +1,3 @@
1
1
  module Odca
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
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.1
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: 2019-12-17 00:00:00.000000000 Z
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.7.7
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