Class: HammerCLI::Options::Normalizers::ListNested
- Inherits:
-
AbstractNormalizer
- Object
- AbstractNormalizer
- HammerCLI::Options::Normalizers::ListNested
- Defined in:
- lib/hammer_cli/options/normalizers.rb
Defined Under Namespace
Classes: Schema
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #completion_type ⇒ Object
- #format(val) ⇒ Object
-
#initialize(schema) ⇒ ListNested
constructor
A new instance of ListNested.
Methods inherited from AbstractNormalizer
#complete, #description, inherited
Constructor Details
#initialize(schema) ⇒ ListNested
Returns a new instance of ListNested.
178 179 180 |
# File 'lib/hammer_cli/options/normalizers.rb', line 178 def initialize(schema) @schema = Schema.new(schema) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
176 177 178 |
# File 'lib/hammer_cli/options/normalizers.rb', line 176 def schema @schema end |
Class Method Details
.common_description ⇒ Object
150 151 152 153 154 |
# File 'lib/hammer_cli/options/normalizers.rb', line 150 def common_description _('Comma separated list of values defined by a schema.') + "\n" + _('JSON is acceptable and preferred way for such parameters') end |
.completion_type ⇒ Object
146 147 148 |
# File 'lib/hammer_cli/options/normalizers.rb', line 146 def completion_type :schema end |
Instance Method Details
#completion_type ⇒ Object
195 196 197 |
# File 'lib/hammer_cli/options/normalizers.rb', line 195 def completion_type super.merge({ schema: schema.description(richtext: false) }) end |
#format(val) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/hammer_cli/options/normalizers.rb', line 182 def format(val) return [] unless val.is_a?(String) && !val.empty? begin JSON.parse(val) rescue JSON::ParserError HammerCLI::CSVParser.new.parse(val).inject([]) do |results, item| next if item.empty? results << KeyValueList.new.format(item) end end end |