ordinare 0.1.4 → 0.2.4

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: 6db1aa209ae60c8a5667d18c7d5c1bd72633c18d
4
- data.tar.gz: f95a237ac4459d7e2983a82c259a2b217a6a6bc5
3
+ metadata.gz: 0abec2f62b5854d233b27991419284c6b49da7c2
4
+ data.tar.gz: 15de8a890b14820fab38f7ca88038a34fdce5043
5
5
  SHA512:
6
- metadata.gz: adb55f68100504ac3802348875159f85b281f773d982b33b62769d9bda438f24815e080b8f157fe7fe2f68cd809fdc55ede340339d177e9625871fff95754790
7
- data.tar.gz: f5f2c7ebc8260d82b2460d36eddc4c35ce97bd4b429ac2dcfbc874165e34cdba641f0b431b5e9f7b05d38866f505b248a8ff9aaa609423e3c9d776749aa995c8
6
+ metadata.gz: e7e0bbb69004f6e926beb08340f0c0ab6ba7f7d2be5127e91561682756001c0f90c72629f04a02c42e525af745f21319b8aa72df67809bfa2c29cba269f3f50f
7
+ data.tar.gz: 5559ef647333336b57d6a19f2642f6a869de5b9104b33ca9d56a414a34bc513cd5633bce0f9e1cfd1b4442ff0f300cd6dc5241dbe29f5be192bf81eda0babd7b
@@ -33,10 +33,46 @@ module Ordinare
33
33
 
34
34
  content = File.readlines(path)
35
35
 
36
- content = content.sort
36
+ ranges_to_sort = find_ranges_of_gems(content)
37
+
38
+ ranges_to_sort.each do |range|
39
+ content[range[:start_index]..range[:end_index]] =
40
+ content[range[:start_index]..range[:end_index]].sort
41
+ end
37
42
 
38
43
  File.open("#{path}.ordinare", "w+") do |file|
39
44
  content.each { |line| file.puts(line) }
40
45
  end
41
46
  end
47
+
48
+ def find_ranges_of_gems(content)
49
+ gems = content.each_with_index.map do |line, index|
50
+ if line.start_with?("gem ")
51
+ index
52
+ end
53
+ end
54
+
55
+ ranges_to_sort = []
56
+ gems.each_with_index do |gem, index|
57
+ current_range = if ranges_to_sort.last && !ranges_to_sort.last[:end_index]
58
+ ranges_to_sort.last
59
+ else
60
+ { :start_index => nil, :end_index => nil }
61
+ end
62
+ start_index = current_range[:start_index]
63
+ end_index = current_range[:end_index]
64
+
65
+ if gem && !gems[index - 1]
66
+ current_range[:start_index] = index
67
+
68
+ ranges_to_sort << current_range
69
+ elsif gem && gems[index - 1] && !gems[index + 1]
70
+ ranges_to_sort.map do |range|
71
+ range[:start_index] == start_index ? current_range[:end_index] = index : range
72
+ range
73
+ end
74
+ end
75
+ end
76
+ ranges_to_sort
77
+ end
42
78
  end
@@ -1,3 +1,3 @@
1
1
  module Ordinare
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ordinare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikola Đuza
@@ -14,16 +14,22 @@ dependencies:
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.6'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: '3.6'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.6'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: '3.6'
27
33
  description: Ordinare sorts gems in your Gemfile alphabetically
28
34
  email: nikolaseap@gmail.com
29
35
  executables: