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



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

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