Class: Dockerc::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/dockerc/normalizer.rb

Instance Method Summary collapse

Instance Method Details

#handle_request_data(h) ⇒ Object



28
29
30
31
32
33
# File 'lib/dockerc/normalizer.rb', line 28

def handle_request_data(h)
  h.inject({}) do |memo, (k,v)|
    memo[handle_request_key(k)] = v
    memo
  end
end

#handle_request_key(s) ⇒ Object



35
36
37
38
# File 'lib/dockerc/normalizer.rb', line 35

def handle_request_key(s)
  parts = s.to_s.split('_')
  parts.map(&:capitalize).join
end

#handle_request_query(h) ⇒ Object



3
4
5
6
7
8
# File 'lib/dockerc/normalizer.rb', line 3

def handle_request_query(h)
  h.inject({}) do |memo,(k,v)|
    memo[handle_request_query_key(k)] = handle_request_query_value(v)
    memo    
  end
end

#handle_request_query_key(s) ⇒ Object



10
11
12
13
14
15
# File 'lib/dockerc/normalizer.rb', line 10

def handle_request_query_key(s)
  parts = s.to_s.split('_')
  parts.map!(&:capitalize)
  parts.first.downcase!
  parts.join
end

#handle_request_query_value(s) ⇒ Object



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

def handle_request_query_value(s)
  case s
  when TrueClass
    1
  when FalseClass
    0
  else
    s
  end
end

#handle_response_data(data) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/dockerc/normalizer.rb', line 51

def handle_response_data(data)
  case data
  when Hash
    handle_response_hash(data)
  when Array
    data.map { |h| handle_response_hash h }
  end
end

#handle_response_hash(h) ⇒ Object



40
41
42
43
44
45
# File 'lib/dockerc/normalizer.rb', line 40

def handle_response_hash(h)
  h.inject({}) do |memo, (k,v)|
    memo[handle_response_hash_param(k)] = v
    memo
  end
end

#handle_response_hash_param(s) ⇒ Object



47
48
49
# File 'lib/dockerc/normalizer.rb', line 47

def handle_response_hash_param(s)
  s.to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym
end