opening_hours_converter 1.13.6 → 1.13.7

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: '08d64cb65cb3b261526debe5bbac2139dc2d18ccfea137eeceaddb5c221a7a09'
4
- data.tar.gz: a6553952b6ea0c7d3f0e87f916a315c7ab9f022bb5c8cb58accae49a32f8d283
3
+ metadata.gz: 323387cf1e5e01948cf29e1e2a8f0037b3b70c827ac5d20e7fd68e557e87ad22
4
+ data.tar.gz: 83f7ca5fa616cb1d53fe156512689540d36624b34988e79cf335f959b6dfc156
5
5
  SHA512:
6
- metadata.gz: 7467758597633280c3863cead517d31fa18ad63dbaf8fca05d5236da2d63001e360ba3ade52f054774436da8e14787fd02e5af330007cebeebc152a96359732e
7
- data.tar.gz: 348168fd8f07315a942162d8313736f8237a196e4fdc84ed150812d0751aa83344c0740fa5330ef59b5499bd6857793ed001625e1c4f56c020c0d28a60138104
6
+ metadata.gz: d89ba9be9286a35eec8eb7b0424be359cf080e303a561241ddfe35ee68702bf48cd70f74a0bfe3c6eaa219b70f6ae27b254490a0ce1de3c61218e91c9fc0a1a5
7
+ data.tar.gz: ab7e7d65a6b9bde071d9030cc3e8d7c8ffcc9cd6280c5e36d3182c0345722ef27a3d37ebc0ab67054a12effb08ae361713f85ee062232158b751ba5501f45e8d
@@ -17,7 +17,7 @@ module OpeningHoursConverter
17
17
 
18
18
  off, start_minute, end_minute = handle_interval(interval)
19
19
 
20
- raise "Invalid interval #{interval.inspect}" if start_minute.nil? && end_minute.nil?
20
+ raise ParseError, "Invalid interval #{interval.inspect}" if start_minute.nil? && end_minute.nil?
21
21
 
22
22
  (start_minute..end_minute).step do |minute|
23
23
  minute_array[minute] = off ? 'off' : true
@@ -125,12 +125,12 @@ module OpeningHoursConverter
125
125
  elsif !(@regex_handler.week_regex =~ wide_range_selector).nil?
126
126
  weeks << get_week(wide_range_selector)
127
127
  else
128
- raise ArgumentError, "Unsupported selector #{wide_range_selector}"
128
+ raise ParseError, "Unsupported selector #{wide_range_selector}"
129
129
  end
130
130
  end
131
131
  end
132
132
 
133
- raise ArgumentError, 'Unreadable string' if @current_token == tokens.length - 1
133
+ raise ParseError, 'Unreadable string' if @current_token == tokens.length - 1
134
134
 
135
135
  # puts "weekdays : #{weekdays}"
136
136
  # puts "weeks : #{weeks}"
@@ -205,7 +205,7 @@ module OpeningHoursConverter
205
205
  end
206
206
 
207
207
  def int_range(max)
208
- raise 'too high' if max > 99
208
+ raise ArgumentError, 'too high' if max > 99
209
209
 
210
210
  base = max / 10
211
211
 
@@ -14,6 +14,10 @@ module OpeningHoursConverter
14
14
  @made_from = made_from
15
15
  end
16
16
 
17
+ def to_s
18
+ "Token(value: #{@value}, type: #{@type}, start_index: #{@start_index})"
19
+ end
20
+
17
21
  def year?
18
22
  integer? && @value.length == 4
19
23
  end
@@ -18,7 +18,7 @@ module OpeningHoursConverter
18
18
  def tokenize
19
19
  counter = 0
20
20
  while @index < @opening_hours_string.length
21
- raise 'ups' if counter > 200
21
+ raise ParseError if counter > 200
22
22
  skip_white_spaces
23
23
  @tokens << handle_string if string?
24
24
 
@@ -67,7 +67,7 @@ module OpeningHoursConverter
67
67
  next
68
68
  end
69
69
 
70
- raise "can't read current token #{current_token}"
70
+ raise ParseError, "can't read current token #{current_token}"
71
71
  end
72
72
  end
73
73
 
@@ -105,7 +105,7 @@ module OpeningHoursConverter
105
105
  value, made_from, type = add_current_token_to(value, type, made_from)
106
106
  next
107
107
  end
108
- raise "you can\'t have two years with just space between them previous token: #{previous_token}, current token: #{current_token}"
108
+ raise ParseError, "you can\'t have two years with just space between them previous token: #{previous_token}, current token: #{current_token}"
109
109
  end
110
110
 
111
111
  if current_token.string?
@@ -309,23 +309,23 @@ module OpeningHoursConverter
309
309
  made_from = [current_token]
310
310
  @index += 1
311
311
 
312
- raise unless current_token.colon?
312
+ raise ParseError unless current_token.colon?
313
313
  value, made_from, type = add_current_token_to(value, type, made_from)
314
314
 
315
- raise unless current_token.time?
315
+ raise ParseError unless current_token.time?
316
316
  value, made_from, type = add_current_token_to(value, type, made_from)
317
317
 
318
- raise unless current_token.hyphen?
318
+ raise ParseError unless current_token.hyphen?
319
319
  value, made_from, type = add_current_token_to(value, type, made_from)
320
320
 
321
321
  # second part of time range
322
- raise unless current_token.time?
322
+ raise ParseError unless current_token.time?
323
323
  value, made_from, type = add_current_token_to(value, type, made_from)
324
324
 
325
- raise unless current_token.colon?
325
+ raise ParseError unless current_token.colon?
326
326
  value, made_from, type = add_current_token_to(value, type, made_from)
327
327
 
328
- raise unless current_token.time?
328
+ raise ParseError unless current_token.time?
329
329
  value, made_from, type = add_current_token_to(value, type, made_from)
330
330
 
331
331
  token(value, type, start_index, made_from)
@@ -6,22 +6,8 @@ module OpeningHoursConverter
6
6
  include Constants
7
7
  extend Utils
8
8
 
9
- def self.weeks_from_index(array_of_indexes, year = Time.now.year)
10
- array_of_indexes.flat_map do |index_or_range|
11
- if index_or_range.is_a?(Hash)
12
- index_or_range[:from].step(index_or_range[:to], index_or_range[:modifier]).map do |index|
13
- week_from_index(index, year)
14
- end
15
- elsif index_or_range.is_a?(Integer)
16
- week_from_index(index_or_range, year)
17
- else
18
- raise ArgumentError, "#{index_or_range} in #{array_of_indexes} is neither an integer nor a Hash"
19
- end
20
- end
21
- end
22
-
23
9
  def self.week_from_index(index, year = Time.now.year)
24
- raise unless index >= 1
10
+ raise ArgumentError unless index >= 1
25
11
 
26
12
  week = first_week(year)
27
13
  offset = (index - 1) * 7
@@ -106,7 +92,7 @@ module OpeningHoursConverter
106
92
  first_day_of_the_week = first_day_of_month - first_wday_of_month
107
93
  first_day_of_the_week + wday + (n - 1) * 7
108
94
  end
109
- raise 'Out of bound' unless date.month == month
95
+ raise ArgumentError, 'Out of bound' unless date.month == month
110
96
 
111
97
  date
112
98
  end
@@ -133,7 +119,7 @@ module OpeningHoursConverter
133
119
  first_day_of_the_week = last_day_of_month - last_wday_of_month
134
120
  first_day_of_the_week + wday
135
121
  end
136
- raise 'Out of bound' unless date.month == month
122
+ raise ArgumentError, 'Out of bound' unless date.month == month
137
123
 
138
124
  date
139
125
  end
@@ -24,7 +24,6 @@ module OpeningHoursConverter
24
24
  years = process_always_holiday(date_range.wide_interval, years)
25
25
  end
26
26
  end
27
-
28
27
  if !date_range.wide_interval.start.nil? && !date_range.wide_interval.start[:year].nil?
29
28
  if date_range.wide_interval.end.nil? || date_range.wide_interval.end[:year].nil? || date_range.wide_interval.start[:year] == date_range.wide_interval.end[:year]
30
29
  if !years[date_range.wide_interval.start[:year]].nil?
@@ -228,14 +227,7 @@ module OpeningHoursConverter
228
227
  end
229
228
  else
230
229
  for year in (DateTime.now.year)..(DateTime.now.year + 1)
231
- if wide_interval.type == 'week'
232
- years[year] ||= Array.new(OSM_MONTHS.length) { |i| Array.new(MONTH_END_DAY[i]) { false } }
233
- WeekIndex.weeks_from_index(wide_interval.indexes, year).each do |interval|
234
- (interval[:from]..interval[:to]).each do |day|
235
- years[year][day.month - 1][day.day - 1] = true
236
- end
237
- end
238
- elsif wide_interval.start.nil?
230
+ if wide_interval.start.nil?
239
231
  years[year] = Array.new(OSM_MONTHS.length) { |i| Array.new(MONTH_END_DAY[i]) { true } }
240
232
  elsif !wide_interval.start[:day].nil?
241
233
  years[year] ||= Array.new(OSM_MONTHS.length) { |i| Array.new(MONTH_END_DAY[i]) { false } }
@@ -370,13 +362,6 @@ module OpeningHoursConverter
370
362
  end
371
363
  end
372
364
  end
373
- elsif wide_interval.type == "week"
374
- year = wide_interval.start&.dig(:year) || Time.now.year # can't process weeks with undefined year
375
- WeekIndex.weeks_from_index(wide_interval.indexes, year).each do |interval|
376
- (interval[:from]..interval[:to]).each do |day|
377
- years[year][day.month - 1][day.day - 1] = true
378
- end
379
- end
380
365
  elsif wide_interval.type == "day"
381
366
  if wide_interval.end.nil? || !wide_interval.end.nil? && wide_interval.start[:month] == wide_interval.end[:month]
382
367
  if wide_interval.end.nil? || !wide_interval.end.nil? && wide_interval.start[:day] == wide_interval.end[:day]
@@ -1,6 +1,7 @@
1
1
  module OpeningHoursConverter
2
2
  require 'date'
3
3
  require_relative './opening_hours_converter/utils'
4
+ require_relative './opening_hours_converter/errors.rb'
4
5
  require_relative './opening_hours_converter/regex_handler'
5
6
  require_relative './opening_hours_converter/date_range'
6
7
  require_relative './opening_hours_converter/token'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opening_hours_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.6
4
+ version: 1.13.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziserman Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2019-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json