Module: Transmission::Utils

Included in:
Arguments, Fields
Defined in:
lib/transmission/utils.rb

Instance Method Summary collapse

Instance Method Details

#is_valid_key?(key, attributes) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
# File 'lib/transmission/utils.rb', line 3

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

#option_key(key, attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/transmission/utils.rb', line 17

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

#option_keys(key) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/transmission/utils.rb', line 9

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