Module: Razor::CLI::Transforms

Defined in:
lib/razor/cli/transforms.rb

Class Method Summary collapse

Class Method Details

.count(arr) ⇒ Object



35
36
37
# File 'lib/razor/cli/transforms.rb', line 35

def count(arr)
  arr.size
end

.count_column(hash) ⇒ Object



32
33
34
# File 'lib/razor/cli/transforms.rb', line 32

def count_column(hash)
  hash['count']
end

.count_hash(hash) ⇒ Object



38
39
40
# File 'lib/razor/cli/transforms.rb', line 38

def count_hash(hash)
  hash.is_a?(Hash) ? hash.keys.size : 0
end

.identity(any) ⇒ Object



4
5
6
# File 'lib/razor/cli/transforms.rb', line 4

def identity(any)
  any
end

.if_present(obj) ⇒ Object



7
8
9
# File 'lib/razor/cli/transforms.rb', line 7

def if_present(obj)
  obj.nil? ? "---" : obj
end

.join_names(arr) ⇒ Object



10
11
12
# File 'lib/razor/cli/transforms.rb', line 10

def join_names(arr)
  (arr.nil? or arr.empty?) ? '(none)' : arr.map { |item| item['name'] }.join(", ")
end

.mac(mac) ⇒ Object



23
24
25
# File 'lib/razor/cli/transforms.rb', line 23

def mac(mac)
  mac ? mac.gsub(/-/, ":") : "---"
end

.name(obj) ⇒ Object



26
27
28
# File 'lib/razor/cli/transforms.rb', line 26

def name(obj)
  obj ? obj['name'] : "---"
end

.name_if_present(obj) ⇒ Object



29
30
31
# File 'lib/razor/cli/transforms.rb', line 29

def name_if_present(obj)
  obj ? obj['name'] : "---"
end

.nested(nested_obj) ⇒ Object



13
14
15
# File 'lib/razor/cli/transforms.rb', line 13

def nested(nested_obj)
  (nested_obj.nil? or nested_obj.empty?) ? '(none)' : nested_obj.to_s
end

.select_name(item) ⇒ Object



20
21
22
# File 'lib/razor/cli/transforms.rb', line 20

def select_name(item)
  item and item['name'] or "---"
end

.shallow_hash(hash) ⇒ Object



16
17
18
19
# File 'lib/razor/cli/transforms.rb', line 16

def shallow_hash(hash)
  (hash.nil? or hash.empty?) ? '(none)' :
      hash.map {|key, val| "#{key}: #{val}"}.join(', ')
end