yoga 0.4.2 → 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
  SHA1:
3
- metadata.gz: d47b133334a8a84e8376462babbbe7ead6a966bd
4
- data.tar.gz: d2b5d18e263caf245c93677658dadb1c5c66f36b
3
+ metadata.gz: 07e30449516ea2a36d8b765b9da9d08d17b3677b
4
+ data.tar.gz: ca0b935fedcd9ebb0213e4650b5d6d9932c450ee
5
5
  SHA512:
6
- metadata.gz: fd9eb5267207071585e630dcf03186a0e7f8ac748b578fc207330a2560544f649573d7ebe299fe4820ec53a473e01fc2980048b9484979fb9cb5781b2576fb32
7
- data.tar.gz: 14c809c089f72ddfd86d64dad0d4834d6d7faabfe0386efcc487550c0c4615cb81ee5c6cd1bced90b92bf462a6182a040737d81567079b64d602116ffb91d57b
6
+ metadata.gz: 0041c1f6f886b0218b7f4cb8f86f94a9c33e659ce81bd24c995755fcb872f08ee1c0b58d67be675ac71462aa8897c4d5a7fb336f7c3062ce1c597f8d96d35cf8
7
+ data.tar.gz: c7dea5a35e57f5490fcf4d5c93f0736276d44ce92dd7edd2b33261ea0fa8514c87777b8ce10a2cb309db8513f5056b7ccbe0dad2df05af411227065231d70ee8
@@ -91,6 +91,9 @@ module Yoga
91
91
  @line == other.line && @column == other.column
92
92
  end
93
93
 
94
+ # rubocop:disable Metrics/AbcSize
95
+ # rubocop:disable Metrics/CyclomaticComplexity
96
+
94
97
  # Unions this location with another location. This creates a new location,
95
98
  # with the two locations combined. A conflict in the file name causes an
96
99
  # error to be raised.
@@ -117,36 +120,28 @@ module Yoga
117
120
  # @raise [::ArgumentError] if other's file isn't the receiver's file.
118
121
  # @param others [Location]
119
122
  # @return [Location]
120
- def union(*others)
121
- others.each do |other|
122
- fail ArgumentError, "Expected #{self.class}, got #{other.class}" \
123
- unless other.is_a?(Location)
124
- fail ArgumentError, "Expected other to have the same file" unless
125
- file == other.file
126
- end
127
-
128
- line = construct_range([@line, *others.map(&:line)])
129
- column = construct_range([@column, *others.map(&:column)])
130
-
131
- Location.new(@file, line, column)
123
+ def union(other)
124
+ fail ArgumentError, "Expected #{self.class}, got #{other.class}" \
125
+ unless other.is_a?(Location)
126
+
127
+ oline = other.line
128
+ ocolumn = other.column
129
+
130
+ file = @file == other.file ? @file : "<unknown>"
131
+ line =
132
+ (@line.first < oline.first ? @line.first : oline.first)..
133
+ (@line.last > oline.last ? @line.last : oline.last)
134
+ column =
135
+ (@column.first < ocolumn.first ? @column.first : ocolumn.first)..
136
+ (@column.last > ocolumn.last ? @column.last : ocolumn.last)
137
+
138
+ Location.new(file, line, column)
132
139
  end
133
140
 
134
141
  alias_method :|, :union
135
142
 
136
143
  private
137
144
 
138
- # Creates a range from a list of ranges. This takes the lowest starting
139
- # value, and the greatest ending value, and creates a new range from that.
140
- #
141
- # @param from [<::Range<::Numeric>>]
142
- # @return [::Range<::Numeric>]
143
- def construct_range(from)
144
- first = from.map(&:first).min
145
- last = from.map(&:last).max
146
-
147
- first..last
148
- end
149
-
150
145
  # Ensures that the given value is a range. If it's numeric, it's turned
151
146
  # into a range with the same starting and ending values. If it's a range,
152
147
  # it's returned. Otherwise, it fails.
@@ -5,5 +5,5 @@ module Yoga
5
5
  # The version of the module.
6
6
  #
7
7
  # @return [::String]
8
- VERSION = "0.4.2"
8
+ VERSION = "0.5.0"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yoga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixture