Sha256: cf61fdcfe4c16111dcbc573aa8a35aedf68a8bf35c870889c23e85883e8569f8

Contents?: true

Size: 577 Bytes

Versions: 3

Compression:

Stored size: 577 Bytes

Contents

require 'byebug'

class AwsEc2List::ParseOption
  include Virtus.model

  attribute :args, Array

  def call
    return {} if args.nil? || args.flatten.empty?
    option_string_to_hash
  end

  private
  def option_string_to_hash
    hash = Hash[*parse_array]

    hash.keys.each do |key|
      hash[key.to_sym] = hash.delete(key).strip
    end

    hash
  end

  def parse_array
    multi_option.map{ |opt| opt.split("=") }.flatten
  end

  def multi_option
    option_string.split("--").reject { |o| o.empty? }
  end

  def option_string
    args.flatten.join(" ")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aws-ec2-list-0.2.4 lib/aws_ec2_list/parse_option.rb
aws-ec2-list-0.2.3 lib/aws_ec2_list/parse_option.rb
aws-ec2-list-0.2.2 lib/aws_ec2_list/parse_option.rb