typeform_data 3.0.0 → 3.0.1

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
  SHA1:
3
- metadata.gz: 3da62092341167802dd4565276637320bc9b4239
4
- data.tar.gz: c60c7c72ddc21e7732f2ea866639f3c404879706
3
+ metadata.gz: 6a29d5216f5bc251d42df766ac5f6ee3453a113e
4
+ data.tar.gz: 824508bc3d4e477d0fbaa7a673fa4abad012c011
5
5
  SHA512:
6
- metadata.gz: 0b423251f537bb0b5a2a041fa2a80f57ffceefd70c33c886c0fdfc4c7f8df52770148c021f03b8f7d5ee8fa3cf04b9b673ef1cdc713eeffafe154f082e6ecf72
7
- data.tar.gz: 1ce2a17d3b448d5a0fa4a2c8aae6d2dcd22026f0590d9d1aaae0a10b652c8114d6a2be4de0bc1d3ecc5f9d9e64443123b11b56e1a2588aa44976b590b5cb4fad
6
+ metadata.gz: d615981da83f83f61f8663bd3c1182de16255b32d01a90080d679d0bfe5be3c2a50646540a0de7d9300f4aeb3a1ae1f91dbb28e1c54e8dbcab76fe740286a924
7
+ data.tar.gz: 84bdecd33b209bfd7c0e2eddfc5687321bc23230a6aa32a11506dfe358ae92a6f5f7534d9ac85a11c292fca3e792433f690fb93effa3a36413a49bb4011a1be0
@@ -28,17 +28,6 @@ module TypeformData
28
28
  # typeform.responses(token: response_token)
29
29
  # end
30
30
 
31
- # In the JSON, answer 'ID's are of the form:
32
- #
33
- # - "textfield_12316024"
34
- # - "listimage_12316029_choice_12322262"
35
- #
36
- # This list may not be exhaustive-- there may be other ID formats not covererd above-- since
37
- # this part of the API isn't mentioned in the documentation.
38
- #
39
- # For our Answer object, we strip out only the 'listimage_12316029' part, giving Answers the
40
- # same specificity as Fields.
41
- #
42
31
  # Use this method to create Answers when initializing a Response.
43
32
  #
44
33
  # @param config [TypeformData::Config]
@@ -60,15 +49,7 @@ module TypeformData
60
49
  # @return [Array<Answer>]
61
50
  def self.from_response_attrs(config, attrs, fields)
62
51
  (attrs[:answers] || attrs['answers']).group_by { |id, _value|
63
- field_id = id.split('_')[1]
64
-
65
- unless field_id && field_id.length.positive?
66
- raise UnexpectedError, 'Falsy field ID for answer(s)'
67
- end
68
-
69
- fields.find { |field| field.id.to_s == field_id }.tap { |matched|
70
- raise UnexpectedError, 'Expected to find a matching field' unless matched
71
- }
52
+ matching_field_for_answer(fields, id)
72
53
  }.map { |field, ids_and_values|
73
54
  # ids_and_values looks like [[id, value], [id, value], ...]
74
55
  values = ids_and_values.map(&:last)
@@ -84,6 +65,23 @@ module TypeformData
84
65
  }
85
66
  end
86
67
 
68
+ # In the JSON, answer 'ID's are of the form:
69
+ #
70
+ # - "textfield_12316024"
71
+ # - "listimage_12316029_choice_12322262"
72
+ #
73
+ # This list may not be exhaustive-- there may be other ID formats not covererd above-- since
74
+ # this part of the API isn't mentioned in the documentation.
75
+ private_class_method def self.matching_field_for_answer(fields, answer_id)
76
+ found = fields.find { |field| field.question_ids.include?(answer_id) }
77
+
78
+ unless found
79
+ raise UnexpectedError, "Expected to find a matching field for Answer ID #{answer_id}"
80
+ end
81
+
82
+ found
83
+ end
84
+
87
85
  end
88
86
 
89
87
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module TypeformData
3
- VERSION = '3.0.0'
3
+ VERSION = '3.0.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typeform_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Wallace
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler