contact_congress_parser 0.0.6 → 0.0.7
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 +4 -4
- data/lib/contact_congress_parser/action.rb +3 -3
- data/lib/contact_congress_parser/field.rb +20 -4
- data/lib/contact_congress_parser/version.rb +1 -1
- data/spec/field_spec.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d01ba03b717555b89223cc3068d3aecc8d01255
|
4
|
+
data.tar.gz: 373699f8700199e8dac8dfd5deca599e96ef8b3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a22c2c8de5d31837a794ba24b710cbc89d489f997ee41b632f31b9ed31b7c002a22631ac7b29aac73fdaeadb4dcfe2e0aaae80d11d3a76aacc80bc347ed26696
|
7
|
+
data.tar.gz: e43876bd5f73eb4af227ad6407765ec16765b4152d04c8e12a7783b4bf98912360997197c69592ada9df98f966b05ea5587f70182eb03498da2fe6f7619f648e
|
@@ -34,11 +34,11 @@ module ContactCongressParser
|
|
34
34
|
def fill_in_args
|
35
35
|
'"' + escape_quotes(@data['selector']) + '"' +
|
36
36
|
', with: ' +
|
37
|
-
field(@data['value'])
|
37
|
+
field(@data['value'], required: @data['required'])
|
38
38
|
end
|
39
39
|
|
40
40
|
def select_args
|
41
|
-
field(@data['value'], options: @data['options'])
|
41
|
+
field(@data['value'], options: @data['options'], required: @data['required'])
|
42
42
|
end
|
43
43
|
|
44
44
|
def choose_args
|
@@ -62,7 +62,7 @@ module ContactCongressParser
|
|
62
62
|
URI.parse(uri).path
|
63
63
|
end
|
64
64
|
|
65
|
-
def field(name, options=
|
65
|
+
def field(name, options={})
|
66
66
|
Field.new(name, options).to_s
|
67
67
|
end
|
68
68
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ContactCongressParser
|
2
2
|
class Field
|
3
|
-
attr_reader :name, :field_options
|
3
|
+
attr_reader :name, :options, :field_options, :required
|
4
4
|
|
5
|
-
def initialize(name, options=
|
5
|
+
def initialize(name, options={})
|
6
6
|
@name = normalize_field_name(name)
|
7
7
|
@options = options
|
8
|
-
@field_options = opts_to_array(options[:options])
|
8
|
+
@field_options = opts_to_array(options[:options])
|
9
9
|
@field_options = escape_opts_quotes(@field_options) if field_options
|
10
10
|
end
|
11
11
|
|
@@ -13,7 +13,15 @@ module ContactCongressParser
|
|
13
13
|
"field(\"#{name}\"#{options_str})"
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def required
|
17
|
+
@required ||= case options[:required]
|
18
|
+
when 'Yes', true then true
|
19
|
+
when 'No', false then false
|
20
|
+
when nil then nil
|
21
|
+
else raise "Unrecognized options[:required] => #{options[:required]}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
17
25
|
def normalize_field_name(name)
|
18
26
|
if name[0] == '$'
|
19
27
|
case name
|
@@ -63,7 +71,15 @@ module ContactCongressParser
|
|
63
71
|
end
|
64
72
|
|
65
73
|
def options_str
|
74
|
+
options_field_options_str + options_required_str
|
75
|
+
end
|
76
|
+
|
77
|
+
def options_field_options_str
|
66
78
|
field_options.nil? ? "" : ", options: [\"" + field_options.join("\", \"") + "\"]"
|
67
79
|
end
|
80
|
+
|
81
|
+
def options_required_str
|
82
|
+
required.nil? ? "" : ", required: #{required}"
|
83
|
+
end
|
68
84
|
end
|
69
85
|
end
|
data/spec/field_spec.rb
CHANGED
@@ -10,17 +10,25 @@ describe Field do
|
|
10
10
|
expect(field.to_s).to match("field(\"name\")")
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'parses field options properly' do
|
14
14
|
field = Field.new('state', options: ['NY', 'CA'])
|
15
15
|
expect(field.to_s).to match("field(\"state\", options: [\"NY\", \"CA\"])")
|
16
16
|
end
|
17
17
|
|
18
|
-
it '
|
18
|
+
it 'parses field options with non-standard classes properly' do
|
19
19
|
hash = Field.new('f', options: {'Opt' => 'Opt'})
|
20
20
|
string = Field.new('f', options: 'Opt')
|
21
21
|
|
22
22
|
expect { hash.to_s }.to_not raise_error
|
23
23
|
expect { string.to_s }.to_not raise_error
|
24
24
|
end
|
25
|
+
|
26
|
+
it 'parses required properly' do
|
27
|
+
true_field = Field.new('f', required: 'Yes')
|
28
|
+
false_field = Field.new('f', required: 'No')
|
29
|
+
|
30
|
+
expect(true_field.to_s).to match("field(\"f\", required: true)")
|
31
|
+
expect(false_field.to_s).to match("field(\"f\", required: false)")
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|