Module: MartSearch::Utils
- Included in:
- Controller, DataSource, Index, IndexBuilder, ProjectUtils
- Defined in:
- lib/martsearch/utils.rb
Overview
Utility module containing generic helper funcions.
Instance Method Summary (collapse)
-
- (Net::HTTP) build_http_client
Sets up a Net::HTTP object.
-
- (Hash) convert_array_to_hash(headers, data)
Utility function to convert an array of data to a hash, given a set of headers to key the hash by (they will be matched by the array index).
Instance Method Details
- (Net::HTTP) build_http_client
Sets up a Net::HTTP object
13 14 15 16 17 18 19 20 21 |
# File 'lib/martsearch/utils.rb', line 13 def build_http_client http_client = Net::HTTP proxy_env = ENV['http_proxy'] || ENV['HTTP_PROXY'] if proxy_env proxy = URI.parse( proxy_env ) http_client = Net::HTTP::Proxy( proxy.host, proxy.port ) end return http_client end |
- (Hash) convert_array_to_hash(headers, data)
Utility function to convert an array of data to a hash, given a set of headers to key the hash by (they will be matched by the array index).
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/martsearch/utils.rb', line 30 def convert_array_to_hash( headers, data ) converted_data = {} headers.each_index do |position| if data[position].nil? or data[position] === "" converted_data[ headers[position] ] = nil else converted_data[ headers[position] ] = data[position] end end return converted_data end |