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.
Instance Method Summary collapse
- #description ⇒ Object
- #format(val) ⇒ Object
-
#initialize(schema) ⇒ ListNested
constructor
A new instance of ListNested.
Methods inherited from AbstractNormalizer
Constructor Details
#initialize(schema) ⇒ ListNested
Returns a new instance of ListNested.
134 135 136 |
# File 'lib/hammer_cli/options/normalizers.rb', line 134 def initialize(schema) @schema = Schema.new(schema) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
132 133 134 |
# File 'lib/hammer_cli/options/normalizers.rb', line 132 def schema @schema end |
Instance Method Details
#description ⇒ Object
138 139 140 141 |
# File 'lib/hammer_cli/options/normalizers.rb', line 138 def description _("Comma separated list of values defined by a schema. See Option details section below.") + "\n" + _("JSON is acceptable and preferred way for complex parameters") end |
#format(val) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/hammer_cli/options/normalizers.rb', line 143 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 |