ooze-parser 0.1.7 → 0.1.10

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
- SHA1:
3
- metadata.gz: f3d6d9f5b2a81fc071bed9f32d21c65d07554beb
4
- data.tar.gz: 1ca9904ce21f3396a00ac70f290218ef9171d1c1
2
+ SHA256:
3
+ metadata.gz: ac6c74a6c7335e7c002ef332684e510c03c569fdc254cdd5f334668513e67548
4
+ data.tar.gz: d63bc4cdf6bfb2dc97825b9446b31f2f862c04a4771de62d40b5556095b1237a
5
5
  SHA512:
6
- metadata.gz: 1ee713e3cf2718b338ca141c5f400f1931ea97c06914fd23f0d376131fdb32300b1f54e049bbf53a7697c7fe111b70b946f98e74e3fae250c3f046c0d5085258
7
- data.tar.gz: dab2f8146b6a16a3096e1423b907aac2d863a18f8671e03ba6869681b9fe3e8bc2333a686e4a6f2b0ad9754a4112a3335a846e82112ed9ee4442e1df51e23563
6
+ metadata.gz: cdd17d4a7b2f0fbe0fe0e10b71f0aff505ff63993e10b2ff72d0d4a3a66d051d6112fc441b513e47478b015fee5d5dc5b3547f4656157bf45cd53509f2ddc096
7
+ data.tar.gz: 69a53428143cb56b7f5be3be74f8f45040fa3e495a42d550ab18098ab312c2d9455ff237a8ecf5f9dc7328d4095c88cee8cb5beeafd2d735747aaf2e859019df
@@ -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
@@ -15,10 +15,10 @@ module Ooz
15
15
 
16
16
  private
17
17
 
18
- def to_hash(arr)
18
+ def to_hash(arr, key: "_id")
19
19
  raise "Sorry, expected Array, given: #{arr.class.name}" if !arr.is_a?(Array)
20
20
  arr.map do |e|
21
- [e._id, e]
21
+ [e.send(key), e]
22
22
  end.to_h
23
23
  end
24
24
 
@@ -6,6 +6,11 @@ module Ooz
6
6
  overridable_const :field_factory_class, Model::FieldFactory
7
7
  overridable_const :force_class, Model::Force
8
8
 
9
+ def tagged?(tag, search_on: :tags)
10
+ haystack = self.send(search_on)
11
+ haystack.include?(tag)
12
+ end
13
+
9
14
  def stages?
10
15
  evolution && evolution.stages&.length > 0
11
16
  end
@@ -35,8 +40,26 @@ module Ooz
35
40
  membranes
36
41
  end
37
42
 
38
- def fields_hash
39
- to_hash(fields)
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
40
63
  end
41
64
 
42
65
  def sections
data/lib/ooz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ooz
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.10"
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.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
@@ -140,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.6.14.1
143
+ rubygems_version: 3.0.3
145
144
  signing_key:
146
145
  specification_version: 4
147
146
  summary: ooze-parser to boost data integration and treatment