typed_form 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/typed_form/form_data/answers.rb +8 -1
- data/lib/typed_form/form_data/question.rb +3 -2
- data/lib/typed_form/version.rb +1 -1
- data/lib/typed_form/virtual_model.rb +18 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53e20316dde02ffffb4d493a7f20b90f96aea947
|
4
|
+
data.tar.gz: a420c807742102952a4b2a2af4e21105b69832d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5490138b490865e105087be1be998b2f6b0e2ba2e78532f921ed13e5658ff16912828ba841491f995e9f7187cffe2bfa2027c2563a7cbf0c3af2167291d0d2d2
|
7
|
+
data.tar.gz: '0659ee90598a0a52163129f1bfe606f656f6ad8fbc2ab999b5210ca869cca284058089063a7dc8fa7ba278693ae7d61ef1b59f3f2c97a775fe2db2bee5e47333'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### [0.1.3] - 2017-03-16
|
4
|
+
|
5
|
+
Adds support for typecasting Yes/No and Terms of Service fields in TypedForm::VirtualModel. Adds "original_answer" field to Questions to preserve original values, either for debugging purposes or for situations where typecasting is not desirable.
|
6
|
+
|
3
7
|
## [0.1.2] - 2017-03-13
|
4
8
|
|
5
9
|
Strips non-breaking whitespace ("\\u00a0") character from typeform data to normalize question/answer searching. Adds support for typecasting date, datetime, and integer objects from Typeform Responses & metadata.
|
@@ -47,7 +47,8 @@ module TypedForm
|
|
47
47
|
Question.with_response_data(
|
48
48
|
question: question,
|
49
49
|
answer: typecast_answer(answer: text_answers, type: question.type),
|
50
|
-
text: extrapolated_question_text(question)
|
50
|
+
text: extrapolated_question_text(question),
|
51
|
+
original_answer: text_answers
|
51
52
|
)
|
52
53
|
end
|
53
54
|
end
|
@@ -106,10 +107,16 @@ module TypedForm
|
|
106
107
|
end
|
107
108
|
end
|
108
109
|
|
110
|
+
def cast_boolean_string(string)
|
111
|
+
string == "1" ? true : false
|
112
|
+
end
|
113
|
+
|
109
114
|
def typecast_answer(answer:, type:)
|
110
115
|
case type
|
111
116
|
when "date" then normalized_date(answer)
|
112
117
|
when "number" then answer.to_i
|
118
|
+
when "yesno" then cast_boolean_string(answer)
|
119
|
+
when "terms" then cast_boolean_string(answer)
|
113
120
|
else answer
|
114
121
|
end
|
115
122
|
end
|
@@ -13,7 +13,7 @@ module TypedForm
|
|
13
13
|
# @attr [Text] answer The extrapolated text for the question
|
14
14
|
class Question
|
15
15
|
attr_reader :ids, :field_id, :original_text
|
16
|
-
attr_accessor :answer, :text
|
16
|
+
attr_accessor :answer, :text, :original_answer
|
17
17
|
|
18
18
|
# Creates a new Question value object, which represents any number of
|
19
19
|
# questions in a Typeform Form that can be logically represented as a
|
@@ -45,9 +45,10 @@ module TypedForm
|
|
45
45
|
#
|
46
46
|
# @return [Question] Question with extrapolated text in questions and
|
47
47
|
# with the answer to the question as an attribute.
|
48
|
-
def self.with_response_data(question:, text:, answer:)
|
48
|
+
def self.with_response_data(question:, text:, answer:, original_answer:)
|
49
49
|
question.dup.tap do |new_question|
|
50
50
|
new_question.answer = answer
|
51
|
+
new_question.original_answer = original_answer
|
51
52
|
new_question.text = text
|
52
53
|
end.freeze
|
53
54
|
end
|
data/lib/typed_form/version.rb
CHANGED
@@ -59,14 +59,26 @@ module TypedForm
|
|
59
59
|
question.answer
|
60
60
|
end
|
61
61
|
|
62
|
-
def typecast_response_field(message,
|
63
|
-
response = message
|
64
|
-
case
|
62
|
+
def typecast_response_field(message, response_field)
|
63
|
+
response = build_response(message, response_field)
|
64
|
+
case response_field
|
65
65
|
when /date/ then DateTime.parse(response)
|
66
66
|
else response
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def build_response(message, response_field)
|
71
|
+
valid_fields = message.singleton_methods.map(&:to_s)
|
72
|
+
|
73
|
+
if valid_fields.include?(response_field)
|
74
|
+
message.send(response_field)
|
75
|
+
else
|
76
|
+
msg = "#{response_field} is not a valid field name for the TypeForm "\
|
77
|
+
"response. Valid fields are: #{valid_fields.join(', ')}"
|
78
|
+
raise ArgumentError, msg
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
70
82
|
def able_to_define?(attr)
|
71
83
|
!self.class.method_defined?(attr) &&
|
72
84
|
attr.to_s.match(/^[a-z_][a-zA-Z_0-9!?]*$/)
|
@@ -76,18 +88,15 @@ module TypedForm
|
|
76
88
|
question_attrs.each do |k, v|
|
77
89
|
next unless able_to_define?(k)
|
78
90
|
|
79
|
-
answer = find_answer_to(v)
|
80
|
-
next if answer.nil?
|
81
|
-
|
82
91
|
define_singleton_method k do
|
83
|
-
|
92
|
+
find_answer_to(v)
|
84
93
|
end
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
88
97
|
def response_attribute_value(messages)
|
89
|
-
messages.split(".").inject(form.response) do |message,
|
90
|
-
typecast_response_field(message,
|
98
|
+
messages.split(".").inject(form.response) do |message, response_field|
|
99
|
+
typecast_response_field(message, response_field)
|
91
100
|
end
|
92
101
|
end
|
93
102
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typed_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Cole
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-03-
|
12
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|