ask_awesomely 0.2.0 → 0.2.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: 9b1872c38eca936853d8a4c749c86825c32e67b3
4
- data.tar.gz: 21e73d3a4c42a1a1b5046c353c893a453c2179cf
3
+ metadata.gz: fe5d4a923eea66566c9ef51c31cbcbb68feaf81a
4
+ data.tar.gz: 33996729a14acccc0613650eb9ff60b97cfca8c6
5
5
  SHA512:
6
- metadata.gz: a71c7706f7c3570b7967ab4b12da84b5ed782f70cc1703b7a805b52c4c1f2c40ef1ea97082db984a35c0b61afec34432b6a9f65bc7a8d7864fc638882cdda631
7
- data.tar.gz: 7677f681ef80f096dde29bcac94aca517c06144e6b5002838296c729f92f638b05c6f319a6ca11646ec0a3f8bc5b899110d0641a5d4a2769e39b13e543922cd9
6
+ metadata.gz: 333ac48991721b15d13bf143c44dd6c828e5fff83c7405a262335e2f690e5a23f7d596cc588dcc97bf5340d28cd097f7774b6f9152e023120af768a30cb4033b
7
+ data.tar.gz: 9c8502a373da9bc3bd33b4458c662f0c7e51ee2d2e4052d671f7b723deccf632df27eb7a217bf47f3a05360dc6a370178f76edcbcfdfa147c54d9412ecc003e6
data/README.md CHANGED
@@ -30,6 +30,7 @@ Build Typeforms awesomely. In Ruby.
30
30
  - [Email](#email)
31
31
  - [Website](#website)
32
32
  - [Legal](#legal)
33
+ - [Custom Designs](#custom-designs)
33
34
  - [Logic Jumps](#logic-jumps)
34
35
  - [Conditional Fields](#conditional-fields)
35
36
  - [Common Customisations](#common-customisations)
@@ -370,7 +371,7 @@ end
370
371
  If you already have a design and would like to re-use it, you can use an ID from the created form.
371
372
 
372
373
  ```ruby
373
- design 12345
374
+ design 12345
374
375
  ```
375
376
 
376
377
  ## Logic Jumps
@@ -1,18 +1,14 @@
1
1
  module AskAwesomely
2
2
  class Field::Dropdown < Field::Field
3
3
 
4
- def initialize(*)
5
- super
6
- @state.choices = []
7
- end
8
-
9
4
  def choice(label)
5
+ @state.choices ||= []
10
6
  @state.choices << Choice.new(label: label)
11
7
  end
12
8
 
13
9
  def in_alphabetical_order
14
10
  @state.alphabetical_order = true
15
11
  end
16
-
12
+
17
13
  end
18
14
  end
@@ -4,10 +4,10 @@ module AskAwesomely
4
4
  prepend JsonBuilder
5
5
 
6
6
  VALID_FIELD_TYPES = %i(
7
- short_text
8
- long_text
9
- multiple_choice
10
- picture_choice
7
+ short_text
8
+ long_text
9
+ multiple_choice
10
+ picture_choice
11
11
  statement
12
12
  dropdown
13
13
  yes_no
@@ -21,29 +21,14 @@ module AskAwesomely
21
21
 
22
22
  attr_reader :state
23
23
 
24
- # todo: make this easier to maintain
25
24
  def self.of_type(type, &block)
26
- field = case type
27
- when :short_text then Field::ShortText
28
- when :long_text then Field::LongText
29
- when :multiple_choice then Field::MultipleChoice
30
- when :picture_choice then Field::PictureChoice
31
- when :statement then Field::Statement
32
- when :dropdown then Field::Dropdown
33
- when :yes_no then Field::YesNo
34
- when :number then Field::Number
35
- when :rating then Field::Rating
36
- when :opinion_scale then Field::OpinionScale
37
- when :email then Field::Email
38
- when :website then Field::Website
39
- when :legal then Field::Legal
40
- else
41
- raise FieldTypeError, "This type of field does not exist, please use one of: #{VALID_FIELD_TYPES.join(", ")}"
42
- end
43
-
25
+ field_type = type.to_s.split('_').map(&:capitalize).join
26
+ field = AskAwesomely::Field.const_get(field_type)
44
27
  field.new(type, &block)
28
+ rescue NameError
29
+ raise FieldTypeError, "This type of field does not exist, please use one of: #{VALID_FIELD_TYPES.join(", ")}"
45
30
  end
46
-
31
+
47
32
  # Allow init with properties common to *all* fields
48
33
  def initialize(type, &block)
49
34
  @state = OpenStruct.new(type: type)
@@ -54,7 +39,7 @@ module AskAwesomely
54
39
  def ask(question)
55
40
  @state.question = question
56
41
  end
57
-
42
+
58
43
  def required
59
44
  @state.required = true
60
45
  end
@@ -62,17 +47,19 @@ module AskAwesomely
62
47
  def tags(*tags)
63
48
  @state.tags = tags
64
49
  end
65
-
50
+
66
51
  def ref(name)
67
52
  @state.ref = name.to_s
68
53
  end
69
54
 
70
55
  def skip(condition)
71
- if cond_if = condition[:if]
56
+ if condition[:if]
57
+ cond_if = condition[:if]
72
58
  @state.skip = -> (context) { cond_if.call(context) == true }
73
59
  end
74
60
 
75
- if cond_unless = condition[:unless]
61
+ if condition[:unless]
62
+ cond_unless = condition[:unless]
76
63
  @state.skip = -> (context) { cond_unless.call(context) != true }
77
64
  end
78
65
  end
@@ -1,12 +1,8 @@
1
1
  module AskAwesomely
2
2
  class Field::MultipleChoice < Field::Field
3
3
 
4
- def initialize(*)
5
- super
6
- @state.choices = []
7
- end
8
-
9
4
  def choice(label)
5
+ @state.choices ||= []
10
6
  @state.choices << Choice.new(label: label)
11
7
  end
12
8
 
@@ -25,6 +21,6 @@ module AskAwesomely
25
21
  def align_vertically
26
22
  @state.vertical_alignment = true
27
23
  end
28
-
24
+
29
25
  end
30
26
  end
@@ -2,15 +2,6 @@ module AskAwesomely
2
2
  class Field::OpinionScale < Field::Field
3
3
 
4
4
  POSSIBLE_STEPS = 5..11
5
-
6
- def initialize(*)
7
- super
8
- @state.label = {
9
- left: nil,
10
- center: nil,
11
- right: nil
12
- }
13
- end
14
5
 
15
6
  def steps(steps)
16
7
  unless POSSIBLE_STEPS.cover?(steps)
@@ -25,16 +16,19 @@ module AskAwesomely
25
16
  end
26
17
 
27
18
  def left_side(label)
19
+ @state.label ||= Hash.new(nil)
28
20
  @state.label[:left_side] = label
29
21
  end
30
22
 
31
23
  def middle(label)
24
+ @state.label ||= Hash.new(nil)
32
25
  @state.label[:center] = label
33
26
  end
34
27
 
35
28
  def right_side(label)
29
+ @state.label ||= Hash.new(nil)
36
30
  @state.label[:right] = label
37
31
  end
38
-
32
+
39
33
  end
40
34
  end
@@ -1,10 +1,6 @@
1
1
  module AskAwesomely
2
2
  class Field::PictureChoice < Field::Field
3
3
 
4
- def initialize(*)
5
- super
6
- end
7
-
8
4
  def choice(label, picture:)
9
5
  @state.choices ||= []
10
6
  @state.choices << Choice.new(label: label, picture: picture)
@@ -29,6 +25,6 @@ module AskAwesomely
29
25
  def align_vertically
30
26
  @state.vertical_alignment = true
31
27
  end
32
-
28
+
33
29
  end
34
30
  end
@@ -1,3 +1,3 @@
1
1
  module AskAwesomely
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask_awesomely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Machin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-06 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk