contact_congress_parser 0.0.8 → 0.0.9

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: b0f8d3f863eccc838fda533ac01475652568e7eb
4
- data.tar.gz: a69134a888c381218e7edad074ee4e5a2cb428a9
3
+ metadata.gz: f606f2a626261c661b7a173b8a4d79741eee103b
4
+ data.tar.gz: ccc6e758a9665417c588b117f9347723fb03887e
5
5
  SHA512:
6
- metadata.gz: c857664dcbe3b7c3f6cc0988812d48b02c7a21288fb431448762985cc606cb28520a2d657994443a48b560b2182d65c65543be702a5c02cabda3e8b015cf7c68
7
- data.tar.gz: 7547db2184ee54fbd4025a9d11203e9341e1e62835f5366eee412a962bd8ff1e627983f177a8c9d18979544c3d4ad44705edc8aa9af942ec179f9901f1f8f051
6
+ metadata.gz: 303ebac0d3da7adb7daf45375b49684de875e721946e7dca3b0656a7daae9dbc7263f088c06e3af153ea370f301c44f057ce4a85adc13b265cf42033b98af0ec
7
+ data.tar.gz: c9ed5abfd075ff8e990d94763fb0abaf7abf641060d16c6e6989c51f4fdbb92ebad121ce0ba15a5d7b1579efce7d97b472217cb89c713462cd6e1445b5ef776c
@@ -5,8 +5,6 @@ module ContactCongressParser
5
5
  def initialize(name, options={})
6
6
  @name = normalize_field_name(name)
7
7
  @options = options
8
- @field_options = opts_to_array(options[:options])
9
- @field_options = escape_opts_quotes(@field_options) if field_options
10
8
  end
11
9
 
12
10
  def to_s
@@ -58,28 +56,51 @@ module ContactCongressParser
58
56
  end
59
57
  end
60
58
 
61
- def opts_to_array(opts)
62
- case opts
63
- when Array then opts
64
- when Hash then opts.keys
65
- when String then [opts]
66
- end
59
+ def options_str
60
+ Options.new(options[:options]).to_s + options_required_str
67
61
  end
68
62
 
69
- def escape_opts_quotes(opts)
70
- opts.map { |str| str.gsub('"', '\"') }
63
+ def options_required_str
64
+ required.nil? ? "" : ", required: #{required}"
71
65
  end
72
66
 
73
- def options_str
74
- options_field_options_str + options_required_str
75
- end
67
+ # Note this is a class for options[:options] not the entire set of options
68
+ # that include options[:required], etc.
69
+ class Options
70
+ def initialize(options)
71
+ @options = options
72
+ if @options
73
+ to_array
74
+ strip
75
+ escape_quotes
76
+ hashify
77
+ end
78
+ end
76
79
 
77
- def options_field_options_str
78
- field_options.nil? ? "" : ", options: [\"" + field_options.join("\", \"") + "\"]"
79
- end
80
+ def to_s
81
+ @options || ''
82
+ end
83
+
84
+ private
85
+ def to_array
86
+ @options = case @options
87
+ when Array then @options
88
+ when Hash then @options.keys
89
+ when String then [@options]
90
+ end
91
+ end
80
92
 
81
- def options_required_str
82
- required.nil? ? "" : ", required: #{required}"
93
+ def strip
94
+ @options.map! { |option| option.strip }
95
+ end
96
+
97
+ def escape_quotes
98
+ @options.map! { |option| option.gsub('"', '\"') }
99
+ end
100
+
101
+ def hashify
102
+ @options = ", options: [\"" + @options.join("\", \"") + "\"]"
103
+ end
83
104
  end
84
105
  end
85
106
  end
@@ -1,3 +1,3 @@
1
1
  module ContactCongressParser
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  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.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikias Kalpaxis