Sha256: 62ada5749c5bc8b91eedd02bf7e2e73d2ca111c4862dff2797aac147f05cb981

Contents?: true

Size: 685 Bytes

Versions: 5

Compression:

Stored size: 685 Bytes

Contents

module Transmission
  module Utils
    def is_valid_key?(key, attributes)
      !attributes.select do |attribute|
        option_keys(key).include? attribute[:field]
      end.empty?
    end

    def option_keys(key)
      split = key.to_s.split '_'
      dashed = split.join '-'
      camelcase = split.collect{|p| p.capitalize}.join
      camelcase = camelcase[0].downcase + camelcase[1..-1]
      [dashed, camelcase]
    end

    def option_key(key, attributes)
      selected = attributes.select do |attribute|
        option_keys(key).include? attribute[:field]
      end
      if selected.size > 0
        selected.first[:field]
      else
        nil
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
transmission-rpc-ruby-0.4.0 lib/transmission/utils.rb
transmission-rpc-ruby-0.3.1 lib/transmission/utils.rb
transmission-rpc-ruby-0.3.0 lib/transmission/utils.rb
transmission-rpc-ruby-0.2.1 lib/transmission/utils.rb
transmission-rpc-ruby-0.2.0 lib/transmission/utils.rb