multi_range 0.0.2 → 0.0.3
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 +4 -4
- data/.rubocop.yml +5 -62
- data/CHANGELOG.md +8 -0
- data/README.md +23 -6
- data/lib/multi_range.rb +17 -3
- data/lib/multi_range/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40f3cff00ed60128e29feff428493d53a4d1045f213bda0716aed7144f6aa9cf
|
4
|
+
data.tar.gz: 4b589504d4a04697e32e3d3ded51649b5e3c26c80c809ed79b75303b631bdd7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47f1e249df764eb7f299e99a7d4f254baac83f7e4a32968ceaef468fca3cf4698f7291eca22b320f875656586e3655e19695e2cc084fc65b22e8a9b7be20211a
|
7
|
+
data.tar.gz: f0641722ac5749d23ac1efc795422d26a02f44cc04cfe48d4a12d549883d83579faef72b9586f6375fa08bf0ebdb0ad9a8273bac9c87994fc21965d6abbb5980
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require:
|
2
2
|
- rubocop-performance
|
3
|
-
- rubocop-rails
|
4
3
|
|
5
4
|
AllCops:
|
6
5
|
DisabledByDefault: true
|
@@ -311,58 +310,6 @@ Performance/StringReplacement:
|
|
311
310
|
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'
|
312
311
|
Enabled: true
|
313
312
|
|
314
|
-
##################### Rails ##################################
|
315
|
-
|
316
|
-
Rails/ActionFilter:
|
317
|
-
Description: 'Enforces consistent use of action filter methods.'
|
318
|
-
Enabled: true
|
319
|
-
|
320
|
-
Rails/Date:
|
321
|
-
Description: >-
|
322
|
-
Checks the correct usage of date aware methods,
|
323
|
-
such as Date.today, Date.current etc.
|
324
|
-
Enabled: true
|
325
|
-
|
326
|
-
Rails/Delegate:
|
327
|
-
Description: 'Prefer delegate method for delegations.'
|
328
|
-
Enabled: true
|
329
|
-
|
330
|
-
Rails/FindBy:
|
331
|
-
Description: 'Prefer find_by over where.first.'
|
332
|
-
Enabled: true
|
333
|
-
|
334
|
-
Rails/FindEach:
|
335
|
-
Description: 'Prefer all.find_each over all.find.'
|
336
|
-
Enabled: true
|
337
|
-
|
338
|
-
Rails/HasAndBelongsToMany:
|
339
|
-
Description: 'Prefer has_many :through to has_and_belongs_to_many.'
|
340
|
-
Enabled: true
|
341
|
-
|
342
|
-
Rails/Output:
|
343
|
-
Description: 'Checks for calls to puts, print, etc.'
|
344
|
-
Enabled: true
|
345
|
-
|
346
|
-
Rails/ReadWriteAttribute:
|
347
|
-
Description: >-
|
348
|
-
Checks for read_attribute(:attr) and
|
349
|
-
write_attribute(:attr, val).
|
350
|
-
Enabled: true
|
351
|
-
|
352
|
-
Rails/ScopeArgs:
|
353
|
-
Description: 'Checks the arguments of ActiveRecord scopes.'
|
354
|
-
Enabled: true
|
355
|
-
|
356
|
-
Rails/TimeZone:
|
357
|
-
Description: 'Checks the correct usage of time zone aware methods.'
|
358
|
-
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
|
359
|
-
Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
|
360
|
-
Enabled: false
|
361
|
-
|
362
|
-
Rails/Validation:
|
363
|
-
Description: 'Use validates :attribute, hash of validations.'
|
364
|
-
Enabled: true
|
365
|
-
|
366
313
|
################## Style #################################
|
367
314
|
|
368
315
|
Layout/AccessModifierIndentation:
|
@@ -452,10 +399,6 @@ Style/BlockDelimiters:
|
|
452
399
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#single-line-blocks'
|
453
400
|
Enabled: true
|
454
401
|
|
455
|
-
Style/BracesAroundHashParameters:
|
456
|
-
Description: 'Enforce braces style around hash parameters.'
|
457
|
-
Enabled: true
|
458
|
-
|
459
402
|
Style/CaseEquality:
|
460
403
|
Description: 'Avoid explicit use of the case equality operator(===).'
|
461
404
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality'
|
@@ -944,12 +887,12 @@ Style/SingleLineBlockParams:
|
|
944
887
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#reduce-blocks'
|
945
888
|
Methods:
|
946
889
|
- reduce:
|
947
|
-
-
|
948
|
-
-
|
890
|
+
- sum
|
891
|
+
- v
|
949
892
|
- inject:
|
950
|
-
-
|
951
|
-
-
|
952
|
-
Enabled:
|
893
|
+
- sum
|
894
|
+
- v
|
895
|
+
Enabled: false
|
953
896
|
|
954
897
|
Style/SingleLineMethods:
|
955
898
|
Description: 'Avoid single-line methods.'
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [upcoming](https://github.com/khiav223577/multi_range/compare/v0.0.2...HEAD) 2020/03/02
|
4
|
+
- [#6](https://github.com/khiav223577/multi_range/pull/6) freeze internal ranges variable (@khiav223577)
|
5
|
+
- [#5](https://github.com/khiav223577/multi_range/pull/5) Add min, max, to_a method (@khiav223577)
|
6
|
+
|
7
|
+
### [v0.0.2](https://github.com/khiav223577/multi_range/compare/v0.0.1...v0.0.2) 2020/03/02
|
8
|
+
- [#4](https://github.com/khiav223577/multi_range/pull/4) Add each, map, index_with methods (@khiav223577)
|
9
|
+
- [#3](https://github.com/khiav223577/multi_range/pull/3) Support passing integer as range (@khiav223577)
|
10
|
+
|
3
11
|
### v0.0.1 2020/03/01
|
4
12
|
- [#2](https://github.com/khiav223577/multi_range/pull/2) Support Ruby 1.8.7 (@khiav223577)
|
5
13
|
- [#1](https://github.com/khiav223577/multi_range/pull/1) Implement MultiRange (@khiav223577)
|
data/README.md
CHANGED
@@ -53,22 +53,39 @@ multi_range.ranges
|
|
53
53
|
|
54
54
|
#### each
|
55
55
|
```rb
|
56
|
-
MultiRange([1..3,
|
57
|
-
# =>
|
56
|
+
MultiRange.new([1..3, 6, 8..9]).each{|s| print s }
|
57
|
+
# => 123689
|
58
58
|
```
|
59
59
|
|
60
60
|
#### map
|
61
61
|
```rb
|
62
|
-
MultiRange([1..3,
|
63
|
-
# => [2, 4, 6,
|
62
|
+
MultiRange.new([1..3, 6, 8..9]).map{|s| s * 2 }
|
63
|
+
# => [2, 4, 6, 12, 16, 18]
|
64
64
|
```
|
65
65
|
|
66
66
|
#### index_with
|
67
67
|
```rb
|
68
|
-
MultiRange([1..3,
|
69
|
-
# => { 1 => true, 2 => true, 3 => true,
|
68
|
+
MultiRange.new([1..3, 6, 8..9]).index_with(true)
|
69
|
+
# => { 1 => true, 2 => true, 3 => true, 6 => true, 8 => true, 9 => true }
|
70
70
|
```
|
71
71
|
|
72
|
+
#### min
|
73
|
+
```rb
|
74
|
+
MultiRange.new([1..3, 6, 8..9]).min
|
75
|
+
# => 1
|
76
|
+
```
|
77
|
+
|
78
|
+
#### max
|
79
|
+
```rb
|
80
|
+
MultiRange.new([1..3, 6, 8..9]).max
|
81
|
+
# => 9
|
82
|
+
```
|
83
|
+
|
84
|
+
#### to_a
|
85
|
+
```rb
|
86
|
+
MultiRange.new([1..3, 6, 8..9]).to_a
|
87
|
+
# => [1, 2, 3, 6, 8, 9]
|
88
|
+
```
|
72
89
|
|
73
90
|
## Development
|
74
91
|
|
data/lib/multi_range.rb
CHANGED
@@ -20,11 +20,11 @@ class MultiRange
|
|
20
20
|
attr_reader :ranges
|
21
21
|
|
22
22
|
def initialize(ranges) # range 要由小到大排序,且各 range 不能重疊
|
23
|
-
@ranges = ranges.map{|s| s.is_a?(Integer) ? s..s : s }
|
23
|
+
@ranges = ranges.map{|s| s.is_a?(Integer) ? s..s : s }.freeze
|
24
24
|
end
|
25
25
|
|
26
26
|
def -(other)
|
27
|
-
new_ranges = @ranges.
|
27
|
+
new_ranges = @ranges.dup
|
28
28
|
|
29
29
|
return MultiRange.new(new_ranges) if new_ranges.empty?
|
30
30
|
return MultiRange.new(new_ranges) if other.min > @ranges.last.max # 大於最大值
|
@@ -66,7 +66,7 @@ class MultiRange
|
|
66
66
|
|
67
67
|
def index_with(default = INDEX_WITH_DEFAULT)
|
68
68
|
if block_given?
|
69
|
-
fail ArgumentError
|
69
|
+
fail ArgumentError, 'wrong number of arguments (given 1, expected 0)' if default != INDEX_WITH_DEFAULT
|
70
70
|
return map{|s| [s, yield(s)] }.to_h
|
71
71
|
end
|
72
72
|
|
@@ -86,4 +86,18 @@ class MultiRange
|
|
86
86
|
return to_enum(:map){ size } if !block_given?
|
87
87
|
return each.map{|s| yield(s) }
|
88
88
|
end
|
89
|
+
|
90
|
+
def to_a
|
91
|
+
each.to_a
|
92
|
+
end
|
93
|
+
|
94
|
+
def min
|
95
|
+
range = @ranges.first
|
96
|
+
return range.min if range
|
97
|
+
end
|
98
|
+
|
99
|
+
def max
|
100
|
+
range = @ranges.last
|
101
|
+
return range.max if range
|
102
|
+
end
|
89
103
|
end
|
data/lib/multi_range/version.rb
CHANGED