ecoportal-api 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07fc08d0dd8f3cb516f4643fa58bdc801630666c7bd67654ec2ed6723e9201f1
4
- data.tar.gz: 71cb65fdb37a4db5dc3e83ecba34c5c20151f90367c515b8a56087cc3192a521
3
+ metadata.gz: 5d6dca34058f1a8327546f9a16051e7e22607240ccdf26efe235a8b1555aef9f
4
+ data.tar.gz: 35dbaf562e87ac39583829425fd29609af248ca72c60c5ad0af4a6bbd137bfab
5
5
  SHA512:
6
- metadata.gz: 85f736a53586f41b1437604d52f9386069f400db761f52c75327ac7117692ff0d5061916520a2b197c84396b604cd43252370dc49a218282bdfb0995447224d8
7
- data.tar.gz: 7daa21cc78da117eaa4cfb60f41b6e5550e0ed596ad3f06dfafaf3a8fbec75278c2f8911791d744654a2a62fe62581b021e2f63bd48b95988ded289d9708cf71
6
+ metadata.gz: b3ea796e5f1d38a7976ca5505ee133c14b9b6c14bed25bd12589c2ba7811c54fad0d20a57eb33c1ce3ec53d18710457cde9ffa6de0f00403d07826d6ee6319ea
7
+ data.tar.gz: 616eb8844afcdf4903ac3005e1ea336a82ccd139fbeac96767b1bd5a2a258f4ce6851e896705e82aae511cd9bc749685d3a4c583eb7186950de3fea4b3a94196
@@ -31,6 +31,10 @@ module Ecoportal
31
31
 
32
32
  private
33
33
 
34
+ def person_schema_class
35
+ Internal::PersonSchema
36
+ end
37
+
34
38
  def person_details_class
35
39
  Internal::PersonDetails
36
40
  end
@@ -39,13 +39,23 @@ module Ecoportal
39
39
  return details
40
40
  end
41
41
 
42
- def add_details(schema_id)
43
- self.details = person_details_class.new
44
- self.details.schema_id = schema_id
42
+ def add_details(schema_or_id)
43
+ self.details = person_details_class.new
44
+ case schema_or_id
45
+ when person_schema_class
46
+ schema_or_id.initialize_details(self.details)
47
+ when String
48
+ self.details.schema_id = schema_id
49
+ end
50
+ self.details
45
51
  end
46
52
 
47
53
  private
48
54
 
55
+ def person_schema_class
56
+ V1::PersonSchema
57
+ end
58
+
49
59
  def person_details_class
50
60
  V1::PersonDetails
51
61
  end
@@ -25,17 +25,21 @@ module Ecoportal
25
25
  @fields_by_alt_id = {}
26
26
  fields.each do |wrapped|
27
27
  @fields_by_id[wrapped.id] = wrapped
28
- @fields_by_id[wrapped.alt_id] = wrapped
28
+ @fields_by_alt_id[wrapped.alt_id] = wrapped
29
29
  end
30
30
  end
31
31
 
32
- def [](id)
32
+ def get_field(id)
33
33
  @fields_by_id or index_fields
34
- (@fields_by_id[id] || @fields_by_alt_id[id])&.value
34
+ @fields_by_id[id] || @fields_by_alt_id[id]
35
+ end
36
+
37
+ def [](id)
38
+ get_field(id)&.value
35
39
  end
40
+
36
41
  def []=(id, value)
37
- @fields_by_id or index_fields
38
- if field = (@fields_by_id[id] || @fields_by_alt_id[id])
42
+ if field = get_field(id)
39
43
  field.value = value
40
44
  end
41
45
  end
@@ -34,6 +34,14 @@ module Ecoportal
34
34
  end
35
35
  end
36
36
 
37
+ def initialize_details(details)
38
+ details.doc["fields"] = fields.map do |field|
39
+ field.doc.slice(*%w[id alt_id name multiple type shared]).merge(
40
+ "value" => field.multiple ? [] : nil
41
+ )
42
+ end
43
+ end
44
+
37
45
  private
38
46
 
39
47
  def schema_field_class
@@ -3,6 +3,31 @@ module Ecoportal
3
3
  class V1
4
4
  class SchemaField < Common::BaseModel
5
5
  passthrough :id, :alt_id, :name, :optional, :shared, :multiple, :type, :options, to: :doc
6
+
7
+ def parse_text(value)
8
+ values = [*value.to_s.lines].map do |line|
9
+ line = line.chomp
10
+ next if line == ""
11
+ case type
12
+ when "text", "phone_number"
13
+ line
14
+ when "number"
15
+ Float(line) rescue return nil, false
16
+ when "boolean"
17
+ %w[true TRUE True Y y YES X x].include?(line)
18
+ when "select"
19
+ return nil, false unless options.include?(line)
20
+ line
21
+ when "date"
22
+ Date.parse(line) rescue return nil, false
23
+ end
24
+ end.compact
25
+ if multiple
26
+ return values, true
27
+ else
28
+ return values.first, true
29
+ end
30
+ end
6
31
  end
7
32
  end
8
33
  end
@@ -1,5 +1,5 @@
1
1
  module Ecoportal
2
2
  module API
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecoportal-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tapio Saarinen