ooze-parser 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ooz/base/field/select.rb +32 -0
- data/lib/ooz/model/ooze.rb +20 -2
- data/lib/ooz/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 231f1190c7c78c3bc1f82fa9f96c664ac8f7397cbd1635590fd7cbba2b00c733
|
4
|
+
data.tar.gz: 8ee25227d7dfae4464be9ada380f1ce05314a466a7660467d538a16c6b4adb4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2675f5fca5402a9e47e09c9306cdfaaa2a66cfb54908d044222ddfe9bf907de05d4c8cc64ea84643c2cc990da20a50f91a6ce83563069953fda34f49965cb7cb
|
7
|
+
data.tar.gz: 61d278211c225b19fb9d10072afd9f1498f4c3a20e18869c595ff138b747a12138ceb75f4f4b5825b49c2152dadcffd314746d548009b0a1ad97883ba17c936e
|
@@ -13,6 +13,38 @@ module Ooz
|
|
13
13
|
module Base
|
14
14
|
class Field
|
15
15
|
class Select
|
16
|
+
class << self
|
17
|
+
# Merges options in `more` into `master` options
|
18
|
+
# @param master [Ooz::Model::Field::Select]
|
19
|
+
# @param more [Ooz::Model::Field::Select, Array<Hash>]
|
20
|
+
# @note it prevents douplicated values
|
21
|
+
def merge_options(master, more, silent: false)
|
22
|
+
if !master.is_a?(Ooz::Model::Field::Select)
|
23
|
+
raise ArgumentError.new("Expecting 'master' to be Ooz::Model::Field::Select. Given: #{master.class}")
|
24
|
+
elsif !more.is_a?(Ooz::Model::Field::Select) && !more.is_a?(Array)
|
25
|
+
raise ArgumentError.new("Expecting 'more' to be Ooz::Model::Field::Select or Array<Hash>. Given: #{more.class}")
|
26
|
+
end
|
27
|
+
opts1 = master.doc["options"]
|
28
|
+
opts2 = more.is_a?(Array)? more : more.doc["options"]
|
29
|
+
|
30
|
+
to_add = opts2.reject do |opt|
|
31
|
+
opts1.any? {|o| o["value"] == opt["value"]}
|
32
|
+
end
|
33
|
+
|
34
|
+
# Some feedback
|
35
|
+
if !silent && more.is_a?(Ooz::Model::Field::Select) && !to_add.empty?
|
36
|
+
puts "Merging more options to the field '#{more.label}':\n"
|
37
|
+
str_opts = to_add.map do |opt|
|
38
|
+
"'#{opt["value"]}' => '#{opt["name"]}'"
|
39
|
+
end.join("\n • ")
|
40
|
+
|
41
|
+
puts " • " + str_opts + "\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
opts1.push(*to_add)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
16
48
|
overridable_const :select_option, Base::Field::Select::Option
|
17
49
|
passthrough :multiple, :flat, :data_type, :other, :other_desc, to: :doc
|
18
50
|
passthrough_arr :options, to: :doc, klass: :select_option
|
data/lib/ooz/model/ooze.rb
CHANGED
@@ -40,8 +40,26 @@ module Ooz
|
|
40
40
|
membranes
|
41
41
|
end
|
42
42
|
|
43
|
-
def fields_hash(key: "_id")
|
44
|
-
|
43
|
+
def fields_hash(key: "_id", silent: true)
|
44
|
+
fields.group_by do |fld|
|
45
|
+
fld.send(key)
|
46
|
+
end.transform_values do |flds|
|
47
|
+
if flds.length == 1
|
48
|
+
flds.first
|
49
|
+
else
|
50
|
+
master = flds.first
|
51
|
+
next master unless master.is_a?(Ooz::Model::Field::Select)
|
52
|
+
rest = flds[1..-1]
|
53
|
+
rest.each do |fld|
|
54
|
+
if fld.is_a?(Ooz::Model::Field::Select)
|
55
|
+
master.other ||= fld.other
|
56
|
+
master.multiple ||= fld.multiple
|
57
|
+
Ooz::Base::Field::Select.merge_options(master, fld, silent: silent)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
master
|
61
|
+
end
|
62
|
+
end
|
45
63
|
end
|
46
64
|
|
47
65
|
def sections
|
data/lib/ooz/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ooze-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.0.
|
143
|
+
rubygems_version: 3.0.3
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: ooze-parser to boost data integration and treatment
|