yalphabetize 0.4.1 → 0.5.0

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
  SHA256:
3
- metadata.gz: 86d76847f2e23ff6fe3cd5a5e58304236f308cd0541a19bd3ab96f7db10bb601
4
- data.tar.gz: 8c00fcc4c33db1396aeae8384d1fc62d12bb27dd5db2ef0e7115c6a1f4ccce09
3
+ metadata.gz: 9fdf038d72b2c031731160247a71b2b29375360fd23b9099f3ce6cb97f022cbc
4
+ data.tar.gz: 54906536110194ebccaf0d04137b68d65939a43951d7785aa3eb33938ef6e5d6
5
5
  SHA512:
6
- metadata.gz: 6e83b56bf3dafb17675575d038cb07fd69c66d7732846eb5ade8379a84d6ac2994471784b2ba6bbdfa306bcbecddcc5d7f175f31c95fd7eaf1b5b509a4d0ba91
7
- data.tar.gz: 37c7d42a08c8a1ac39bfc7bdfb4ce65ec9a658884bbc433df5504f636a9797ad1695bffca1847d7a651331b9929f72bf3a2253f258be03383319e67857af0039
6
+ metadata.gz: 6d9cbba9a9b4775f275e46f85750517a23ecb552b69a0f53993377bdf1e2a4a6a52ea44b89d3ca9fae276330e909be376cea3e10977fb1c26029352bb2b32ef4
7
+ data.tar.gz: eea1b0ce802afd10154823735d675a1e7427a28bec2611017fec957fbaed28c3eff3a66a62ab6606ee31a398f9d9fbfc23baa09d3d0f217a3578911fb1204abd
@@ -8,24 +8,17 @@ module Yalphabetize
8
8
  end
9
9
 
10
10
  def call
11
- transform(stream_node)
12
- alphabetize(stream_node)
13
- stream_node
11
+ stream_node.select(&:mapping?).each do |node|
12
+ pair_up_children(node)
13
+ alphabetize_children(node)
14
+ unpair_children(node)
15
+ end
14
16
  end
15
17
 
16
18
  private
17
19
 
18
20
  attr_reader :stream_node, :order_checker_class
19
21
 
20
- def alphabetize(node)
21
- if node.mapping?
22
- alphabetize_children(node)
23
- unpair_children(node)
24
- end
25
-
26
- node.children&.each { |child_node| alphabetize(child_node) }
27
- end
28
-
29
22
  def alphabetize_children(node)
30
23
  node.children.sort! do |a, b|
31
24
  order_checker_class.compare(a.first.value, b.first.value)
@@ -33,20 +26,7 @@ module Yalphabetize
33
26
  end
34
27
 
35
28
  def unpair_children(node)
36
- children_clone = node.children.dup
37
-
38
- children_clone.each do |slice|
39
- node.children.push(*slice)
40
- node.children.shift
41
- end
42
- end
43
-
44
- def transform(node)
45
- node.children&.each(&method(:transform))
46
-
47
- return unless node.mapping?
48
-
49
- pair_up_children(node)
29
+ node.children.flatten!
50
30
  end
51
31
 
52
32
  def pair_up_children(node)
@@ -54,8 +34,7 @@ module Yalphabetize
54
34
 
55
35
  children_clone.each_slice(2) do |slice|
56
36
  node.children.push(slice)
57
- node.children.shift
58
- node.children.shift
37
+ 2.times { node.children.shift }
59
38
  end
60
39
  end
61
40
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # ABab
3
4
  module Yalphabetize
4
5
  module OrderCheckers
5
6
  class CapitalizedFirstThenAlphabetical < Base
6
7
  def self.compare(string, other_string)
7
- (string <=> other_string)
8
+ string <=> other_string
8
9
  end
9
10
  end
10
11
  end
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # abAB
3
4
  module Yalphabetize
4
5
  module OrderCheckers
5
6
  class CapitalizedLastThenAlphabetical < Base
6
7
  def self.compare(string, other_string)
7
- (string.swapcase <=> other_string.swapcase)
8
+ string.swapcase <=> other_string.swapcase
8
9
  end
9
10
  end
10
11
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Yalphabetize
4
4
  module OrderCheckers
5
- DEFAULT = CapitalizedFirstThenAlphabetical
6
-
7
5
  TOKEN_MAPPING = {
8
6
  'abAB' => CapitalizedLastThenAlphabetical,
9
7
  'aAbB' => AlphabeticalThenCapitalizedLast,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Version
5
- STRING = '0.4.1'
5
+ STRING = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yalphabetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Jenkins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-05 00:00:00.000000000 Z
11
+ date: 2022-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: psych
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: factory_bot
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -94,8 +80,8 @@ dependencies:
94
80
  - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '0'
97
- description:
98
- email:
83
+ description:
84
+ email:
99
85
  executables:
100
86
  - yalphabetize
101
87
  extensions: []
@@ -124,11 +110,11 @@ files:
124
110
  - lib/yalphabetize/writer.rb
125
111
  - lib/yalphabetize/yalphabetizer.rb
126
112
  - lib/yalphabetize/yaml_finder.rb
127
- homepage:
113
+ homepage:
128
114
  licenses: []
129
115
  metadata:
130
116
  rubygems_mfa_required: 'true'
131
- post_install_message:
117
+ post_install_message:
132
118
  rdoc_options: []
133
119
  require_paths:
134
120
  - lib
@@ -144,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
130
  version: '0'
145
131
  requirements: []
146
132
  rubygems_version: 3.0.3.1
147
- signing_key:
133
+ signing_key:
148
134
  specification_version: 4
149
135
  summary: Alphabetize your YAML files
150
136
  test_files: []