yahsort 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1978f669d284eb853bae1d519a93a773e19b85db
4
- data.tar.gz: 688a5c61af76eb40b0ab345659e07167931a5479
3
+ metadata.gz: 1048abd2ea5d541a2dfc241314df602378ae813a
4
+ data.tar.gz: a5820ffd6840dbacf45506f28161d0966ea317c1
5
5
  SHA512:
6
- metadata.gz: 6017c77abb3490c2f06184fc0120d104499bf9742747c657115a8e973a6e0e98b407dbc037c408de9b75462fca7251b916a2ead0cb94440472511b4ec0b1baa9
7
- data.tar.gz: 69e0d25017e37963b09977e516d4fd43c90a8f07c1361a922c3c4fd8028f3addee32ce2eb0a1c942331a1a58a9a3cf4a051576fe32929b75fda3ffef0dae031b
6
+ metadata.gz: 8d261adcd6c1c383de360ddaa61db2f70d81a67bd6244d5d85005419ef1aab3560475124e98f98d9d04c7aaf11ed43674446edd084e563b8eb8faf28554622e1
7
+ data.tar.gz: 1911b7473bd84f2f4d70e662ecfe78cc687d98c5a87d31027401ad38742acaf12bda4a8c3f7af6e68ecfd69ca9567c0baf482eb5ae7f97bc04a0eb719b356169
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Easier to read sorted list of hostnames for those who still care* :)
4
4
 
5
+ Ofcourse you don't need this if you use zero padded hostnames - web01, web02
6
+
5
7
  Usually
6
8
 
7
9
  ```
@@ -35,7 +37,7 @@ Or install it yourself as:
35
37
  ```
36
38
  require 'yahsort'
37
39
 
38
- puts %w{ web1 web10 web11 web2 }.sort
40
+ puts %w{ web1 web10 web11 web2 }.sort &Yahsort.sorter
39
41
  ```
40
42
 
41
43
  ## Contributing
@@ -46,4 +48,4 @@ puts %w{ web1 web10 web11 web2 }.sort
46
48
  4. Push to the branch (`git push origin my-new-feature`)
47
49
  5. Create a new Pull Request
48
50
 
49
- *[Stop worrying about prodweb001](http://www.slideshare.net/AmazonWebServices/stop-worrying-about-prodweb001-and-start-loving-i98fb9856-arc201-aws-reinvent-2013)
51
+ *[Stop worrying about prodweb001](http://www.slideshare.net/AmazonWebServices/stop-worrying-about-prodweb001-and-start-loving-i98fb9856-arc201-aws-reinvent-2013)
@@ -0,0 +1,8 @@
1
+ module Yahsort
2
+ def self.fqdn_sorter
3
+ pattern = Yahsort::PATTERN + '\.'
4
+ regex = Regexp.new(pattern)
5
+
6
+ self.sorter(regex=regex)
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Yahsort
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/yahsort.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  require "yahsort/version"
2
+ require "yahsort/helper"
2
3
 
3
4
  module Yahsort
4
5
  # dig should indicate the 'digits'
5
6
  # sec is secondary idx, number based match is done on same secondaries
6
7
  # db1 api2 ==> api2, db1
8
+ # prod0api1 ---> secondary = prod0api, dig = 1
9
+ PATTERN = '^(?<sec>\w*\D)(?<dig>\d+)'
10
+ REGEX = Regexp.new(PATTERN)
7
11
 
8
- PATTERN = %r{(?<sec>\D)(?<dig>\d+)$}
9
-
10
- def self.sorter(regex=PATTERN, secondary_precedence=true)
12
+ def self.sorter(regex=REGEX, secondary_precedence=true)
11
13
 
12
14
  sorter = lambda do |x,y|
13
15
  reg = regex
data/spec/yahsort_spec.rb CHANGED
@@ -20,5 +20,38 @@ describe Yahsort do
20
20
  expect(h.sort &Yahsort.sorter).to eq(%w{api2 api10 db1 db10})
21
21
  end
22
22
 
23
- #todo match secondary & regex params
23
+ it 'works with padded 0s 001,002' do
24
+ h = %w{ web002 web001 web003}
25
+ expect(h.sort &Yahsort.sorter).to eq(%w{web001 web002 web003})
26
+
27
+ h = %w{ api1 web010 web000 api10}
28
+ expect(h.sort &Yahsort.sorter).to eq(%w{api1 api10 web000 web010})
29
+
30
+ end
31
+
32
+
33
+ fqdn_unsorted = %w{ web2.1domain web10.1domain web1.2domain}
34
+ fqdn_sorted = %w{web1.2domain web2.1domain web10.1domain}
35
+
36
+ it 'does not work with fqdn by default' do
37
+ expect(fqdn_unsorted.sort &Yahsort.sorter).not_to eq(fqdn_sorted)
38
+ end
39
+
40
+ it 'works with fqdn using helper' do
41
+ expect(fqdn_unsorted.sort &Yahsort.fqdn_sorter).to eq(fqdn_sorted)
42
+ end
43
+
44
+ it "works with additional digits" do
45
+ h = %w{stag1api10 stag1api2 stag2api10 stag2api1 stag2api2}
46
+ h_sorted = %w{stag1api2 stag1api10 stag2api1 stag2api2 stag2api10 }
47
+ expect(h.sort &Yahsort.sorter).to eq(h_sorted)
48
+ end
49
+
50
+ it "works with longer fqdns with additional ." do
51
+ h = %w{dev2xcn10.c26.tree.top.com dev2xcn11.c26.tree.top.com dev2xcn2.c26.tree.top.com}
52
+ h_sorted = %w{dev2xcn2.c26.tree.top.com dev2xcn10.c26.tree.top.com dev2xcn11.c26.tree.top.com}
53
+ expect(h.sort &Yahsort.fqdn_sorter).to eq(h_sorted)
54
+ end
55
+
56
+ #todo match secondary_precedence
24
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yahsort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manas Gupta
@@ -67,6 +67,7 @@ files:
67
67
  - README.md
68
68
  - Rakefile
69
69
  - lib/yahsort.rb
70
+ - lib/yahsort/helper.rb
70
71
  - lib/yahsort/version.rb
71
72
  - spec/spec_helper.rb
72
73
  - spec/yahsort_spec.rb