aws-ec2-list 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39afd21079fb63bf6c2dd4ea8bd988e60a7f400b
4
- data.tar.gz: fd6958f76f969412721051787d4104b6cb2ca8fb
3
+ metadata.gz: c884601b450da63b2a0eb2ece02707d3e3ffc95a
4
+ data.tar.gz: 9efa8070081e2b4ec70a8e9c398425268202ad19
5
5
  SHA512:
6
- metadata.gz: 5a536dce47077358714f094fb6c8210d13c4d8674d80d1a23fb63294ca805c45e5a4799b827a47146bfef1edf912889917ea7a8769f64124da98757f3ffb9df0
7
- data.tar.gz: 52208505e4d452000e786340f18ce2ae5c65fcfa25113c2e2fc4d497af52ae30a52fd5e466ef338e30f8bc54f16a9869a88866b29996fd2ca93e568f75f3fa4b
6
+ metadata.gz: 82a6e783a3d50e5fbd63fc8e1938450df5d32cb4c422e13db695d18c83f2fc983150fe68a99a64e904619f2f36b9c8263dbfafb3692da1766645c856a08c915a
7
+ data.tar.gz: a7205b841f4e856a754331f6df94d6beaf622f6ac1ab2638447765d35c19d90e34c5e00c8f830420fe2e38f80051a1618d1e3e210f51287cc5f57ae247f5df60
@@ -5,44 +5,10 @@ require 'tabularize'
5
5
 
6
6
  module AwsEc2List
7
7
  def self.call(*args)
8
- defaults = parse_args(args)
9
- if defaults
10
- DescribeInstances.new(defaults).call
11
- else
12
- DescribeInstances.new.call
13
- end
14
- end
15
-
16
- private
17
- def self.parse_args(args)
18
- return nil if args.empty?
19
- return args.first if args.first.is_a?(Hash)
20
- option_string, default_args = args
21
-
22
- option_string = option_string.first
23
-
24
- if option_string && default_args
25
- option_hash = option_string_to_hash(option_string)
26
- option_hash.merge(default_args)
27
-
28
- elsif option_string
29
- option_string_to_hash(option_string)
30
-
31
- end
32
- end
33
-
34
- def self.option_string_to_hash(option_string)
35
- option_array = option_string.split("--").reject { |o| o.empty? }
36
- option_array = option_array.map{ |opt| opt.split("=") }.flatten
37
-
38
- option_hash = Hash[*option_array]
39
-
40
- option_hash.keys.each do |key|
41
- option_hash[key.to_sym] = option_hash.delete(key)
42
- end
43
-
44
- option_hash
8
+ defaults = ParseOption.new(args: args).call
9
+ DescribeInstances.new(defaults).call
45
10
  end
46
11
  end
47
12
 
48
13
  require_relative "aws_ec2_list/describe_instances"
14
+ require_relative "aws_ec2_list/parse_option"
@@ -0,0 +1,35 @@
1
+ require 'byebug'
2
+
3
+ class AwsEc2List::ParseOption
4
+ include Virtus.model
5
+
6
+ attribute :args, Array
7
+
8
+ def call
9
+ return {} if args.nil? || args.flatten.empty?
10
+ option_string_to_hash
11
+ end
12
+
13
+ private
14
+ def option_string_to_hash
15
+ hash = Hash[*parse_array]
16
+
17
+ hash.keys.each do |key|
18
+ hash[key.to_sym] = hash.delete(key).strip
19
+ end
20
+
21
+ hash
22
+ end
23
+
24
+ def parse_array
25
+ multi_option.map{ |opt| opt.split("=") }.flatten
26
+ end
27
+
28
+ def multi_option
29
+ option_string.split("--").reject { |o| o.empty? }
30
+ end
31
+
32
+ def option_string
33
+ args.flatten.join(" ")
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module AwsEc2List
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ec2-list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - pauloancheta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -116,6 +116,7 @@ files:
116
116
  - lib/aws_ec2_list.rb
117
117
  - lib/aws_ec2_list/describe_instances.rb
118
118
  - lib/aws_ec2_list/instance.rb
119
+ - lib/aws_ec2_list/parse_option.rb
119
120
  - lib/aws_ec2_list/version.rb
120
121
  homepage: https://github.com/pauloancheta/aws-ec2-list
121
122
  licenses: