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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bedac01b6c721845094a5cf42b7c66fb3297b36
4
- data.tar.gz: f5d5b9c753f9943848b6f1e9e1a4fc63d0b62421
3
+ metadata.gz: 9d01ba03b717555b89223cc3068d3aecc8d01255
4
+ data.tar.gz: 373699f8700199e8dac8dfd5deca599e96ef8b3c
5
5
  SHA512:
6
- metadata.gz: 5e5acfd0f3a38131f339fdfb7f39ca5dc7a0264e44761acd9322c3b5f9f126e681cbe737e1534630843d58baded374505c23fcee59523ae06f3c60126e331d7b
7
- data.tar.gz: c58407f68e87f6982433afeb355444cfbbabfcdafb2334c7fa3ae56b92dc0f407c2c64c71ef9a67cca43ca55c9046142fa8a786487163430958e647496d3eb0d
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=nil)
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=nil)
5
+ def initialize(name, options={})
6
6
  @name = normalize_field_name(name)
7
7
  @options = options
8
- @field_options = opts_to_array(options[:options]) if 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
- private
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
@@ -1,3 +1,3 @@
1
1
  module ContactCongressParser
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  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 'handles options properly' do
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 'handles options with non-standard classes properly' do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contact_congress_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikias Kalpaxis