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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1883bd7308b1e95264ee71c5600508957c1599cdee0c3876170d357bbe6a27f5
4
- data.tar.gz: 207722da6b7f6dbaa9439dfbb0681c5b6ca6598517f85a13bbb4ed06ad9b2067
3
+ metadata.gz: 231f1190c7c78c3bc1f82fa9f96c664ac8f7397cbd1635590fd7cbba2b00c733
4
+ data.tar.gz: 8ee25227d7dfae4464be9ada380f1ce05314a466a7660467d538a16c6b4adb4d
5
5
  SHA512:
6
- metadata.gz: 4cbdb49a3044b071ccd5b651c6ab9ba4df5c269be139764ce7d6e8b3578eb130c12871a7894eec5181494c2afd74fbf90675d217abfae3507e7ecbb3337842e4
7
- data.tar.gz: f250a71fdd094f1413a0bcc6a70f9c7a30e29bd321b0b02939b8361b8532cde455442cb6dfe77f29d499b6b78b041665b98ab206b45b8cab8dc6acdfe38a6c03
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
@@ -40,8 +40,26 @@ module Ooz
40
40
  membranes
41
41
  end
42
42
 
43
- def fields_hash(key: "_id")
44
- to_hash(fields, key: key)
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
@@ -1,3 +1,3 @@
1
1
  module Ooz
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
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.8
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.4
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