hets_options.rb revision be16f35e063c5c6d4fa08018600d206322bc0c19
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallynmodule Hets
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn class HetsOptions
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn attr_reader :options
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def self.from_hash(hash)
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn new(hash['options'])
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
9afe19d634946d50eab30e3b90cb5cebcde39eeaDaniel Lezcano
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def initialize(opts = {})
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn @options = opts.dup
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn prepare
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def add(**opts)
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn @options.merge!(opts.dup)
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn prepare
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn protected
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def prepare
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn remove_nil_fields
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber prepare_url_catalog
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def remove_nil_fields
7f95145833bb24f54e037f73ecc37444d6635697Dwight Engen nil_valued_keys = @options.keys.select { |key| @options[key].nil? }
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn nil_valued_keys.each { |key| @options.delete(key) }
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn def prepare_url_catalog
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn @options[:'url-catalog'].try(:compact!)
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn if @options[:'url-catalog'].blank?
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn @options.delete(:'url-catalog')
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn end
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallynend
11cddd70eb8c285287b73562ba4208d74e1b9fdeSerge Hallyn