Class: HammerCLI::Options::Normalizers::ListNested::Schema

Inherits:
Array
  • Object
show all
Defined in:
lib/hammer_cli/options/normalizers.rb

Instance Method Summary collapse

Instance Method Details

#description(richtext: true) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/hammer_cli/options/normalizers.rb', line 158

def description(richtext: true)
  '"' + reduce([]) do |schema, nested_param|
    name = nested_param.name
    name = HighLine.color(name, :bold) if nested_param.required? && richtext
    values = nested_param.validator.scan(/<[^>]+>[\w]+<\/?[^>]+>/)
    value_pattern = if values.empty?
                      "<#{nested_param.expected_type.downcase}>"
                    else
                      values = values.map do |value|
                        value.gsub(/(<\/?[^>]+>)*([\.,]*)*/, '')
                      end
                      "[#{values.join('|')}]"
                    end
    schema << "#{name}=#{value_pattern}"
  end.join('\,').concat(', ... "')
end