Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/wavefront-cli/stdlib/array.rb,
lib/wavefront-cli/output/hcl/stdlib/array.rb
Overview
Extensions to stdlib Array
Instance Method Summary collapse
-
#longest_value_of(key) ⇒ Integer
The length of the longest value in an array of hashes with the given key.
-
#max_length ⇒ Integer
The length of the longest string or symbol in an array.
-
#to_hcl_list ⇒ String
Turn an array into a string which represents an HCL list.
-
#to_hcl_obj(indent = 0) ⇒ String
Turn an array into a string which represents an HCL object.
Instance Method Details
#longest_value_of(key) ⇒ Integer
Returns the length of the longest value in an array of hashes with the given key.
20 21 22 |
# File 'lib/wavefront-cli/stdlib/array.rb', line 20 def longest_value_of(key) map { |v| v[key] }.max_length end |
#max_length ⇒ Integer
Returns the length of the longest string or symbol in an array.
9 10 11 12 13 |
# File 'lib/wavefront-cli/stdlib/array.rb', line 9 def max_length return 0 if empty? map { |x| x.to_s.length }.max end |
#to_hcl_list ⇒ String
Turn an array into a string which represents an HCL list
11 12 13 |
# File 'lib/wavefront-cli/output/hcl/stdlib/array.rb', line 11 def to_hcl_list "[#{join(',')}]" end |
#to_hcl_obj(indent = 0) ⇒ String
Turn an array into a string which represents an HCL object
18 19 20 21 22 23 |
# File 'lib/wavefront-cli/output/hcl/stdlib/array.rb', line 18 def to_hcl_obj(indent = 0) outpad = ' ' * indent inpad = ' ' * (indent + 2) "\n#{outpad}{\n#{inpad}" + join("\n#{inpad}") + "\n#{outpad}}" end |