Sha256: ac7778c172bab3fcc2bcb55c7dd784a0bf5f01be437dbf250a9d1dd822d0a0e9

Contents?: true

Size: 822 Bytes

Versions: 2

Compression:

Stored size: 822 Bytes

Contents

module Trav3
  class Options
    def initialize(**args)
      build(**args)
    end

    def opts
      if @opts.empty?
        ""
      else
        "?#{@opts.join('&')}"
      end
    end

    def build(**args)
      @opts ||= []

      for (key, value) in args
        @opts = @opts.keep_if {|a, _| (eval ki)[a] }
        @opts.push(pb[key, value])
      end
    end

    def remove(key)
      @opts = @opts.keep_if {|a, _| (eval ki)[a] }
    end

    def +(other)
      raise ArgumentError, "Invalid type provided." unless other.is_a?(Options)
      @opts += other.instance_variable_get(:@opts)
    end

    def to_s
      opts
    end

    def pb
      lambda {|param, arg| "#{param}=#{arg}" }
    end
    private :pb

    def ki
      'lambda {|item| !(/^#{key}=/ === "#{item}") }'
    end
    private :ki
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trav3-0.0.2 lib/trav3/options.rb
trav3-0.0.1 lib/trav3/options.rb