opening_hours_converter 1.6.0 → 1.6.1

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: 55f6b611b6d6c7dee28596d842441e9201b69866
4
- data.tar.gz: c20fa4d736826c39c4625ae2cac7a4497fa3ee24
3
+ metadata.gz: d0ad64a12cda6b180b7ab2a4a6d9e7aacf712b73
4
+ data.tar.gz: efb6a8c5930dc03ff1346813208df516b550ad38
5
5
  SHA512:
6
- metadata.gz: ce5333e34fef43072928e868b3e66f92543acf80c5af99dc517dcb385b9d26597765cc18e4db60eeafca013b0bf927f365fedcf6144ed459d1bb36e95137ff29
7
- data.tar.gz: 529acd00a440bdc7d3947cea333324a5f4a87acae235dfa1be4d811a1278a5cd29582b35f9d9961a297c4515e40a7fa35673dee3321330abc404511fbe83629a
6
+ metadata.gz: 82c5844c495b9489de4202439c2ffcb7d3fdd5bad1f7d8a8e49c4a56b1e466ea62a3676455f4608c5fe12bc5dacf0c8905635afec76cde44ec7490dd93d748eb
7
+ data.tar.gz: 35b64100a3ac4b10a194190f07ad64e6c9060a0fabae4a1048e23d6ec25dd48f5b93bfcf36a09fd8afdbef832cc453d130ae6ac87ea79d775a62e11038c00f91
@@ -15,6 +15,7 @@ module OpeningHoursConverter
15
15
  @RGX_WEEKDAY = /^(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH))(,(((Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?)|(PH)))*$/
16
16
  @RGX_HOLIDAY = /^(PH|SH|easter)$/
17
17
  @RGX_WD = /^(Mo|Tu|We|Th|Fr|Sa|Su)(\-(Mo|Tu|We|Th|Fr|Sa|Su))?$/
18
+ @RGX_DAY = /^([012]?[0-9]|3[01])(\-[012]?[0-9]|3[01])?$/
18
19
  @RGX_YEAR = /^(\d{4})(\-(\d{4}))?$/
19
20
  @RGX_YEAR_PH = /^(\d{4})( PH|(\-(\d{4}) PH))\:?$/
20
21
  @RGX_YEAR_MONTH_DAY = /^(\d{4}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([012]?[0-9]|3[01])(\-((\d{4}) )?((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) )?([012]?[0-9]|3[01]))?\:?$/
@@ -579,31 +580,52 @@ module OpeningHoursConverter
579
580
  def tokenize(block)
580
581
  if block.split('"').length > 1
581
582
  comment = block.split('"')[1]
582
- tokens = block.split('"')[0].split(/\s|,/)
583
- tokens << "\"#{comment}\""
584
- merge_weekdays_tokens(tokens)
583
+
584
+ groups = block.split('"')[0].split(',').map { |s| s.split(' ') }
585
+ groups[-1] << "\"#{comment}\""
586
+
587
+ merge_groups(groups)
585
588
  else
586
- merge_weekdays_tokens(block.split(/\s|,/))
589
+ merge_groups(block.split(',').map { |s| s.split(' ') })
587
590
  end
588
591
  end
589
592
 
590
- def merge_weekdays_tokens(tokens)
593
+ def merge_groups(groups)
591
594
  new_tokens = []
592
- to_merge = []
593
- tokens.each_with_index do |token, index|
594
- if is_weekday?(token)
595
- to_merge << token
596
- if index == tokens.length - 1
597
- new_tokens << to_merge.join(',')
595
+ weekday_merge = []
596
+ wide_interval_merge = []
597
+ merged_wide_interval = []
598
+ groups.each_with_index do |group, group_index|
599
+ if !wide_interval_merge.empty?
600
+ merged_wide_interval += [wide_interval_merge.join(' ')]
601
+ wide_interval_merge = []
602
+ end
603
+ group.each_with_index do |token, token_index|
604
+ if !wide_interval_merge.empty? && !is_part_of_wide_interval?(token)
605
+ merged_wide_interval += [wide_interval_merge.join(' ')]
606
+ wide_interval_merge = []
607
+ new_tokens << merged_wide_interval.join(',')
608
+ end
609
+ if is_weekday?(token)
610
+ weekday_merge << token
611
+ if token_index == group.length - 1 && group_index == groups.length - 1
612
+ new_tokens << weekday_merge.join(',')
613
+ end
614
+ elsif !weekday_merge.empty?
615
+ new_tokens << weekday_merge.join(',')
616
+ new_tokens << token
617
+ weekday_merge = []
618
+ elsif is_part_of_wide_interval?(token)
619
+ wide_interval_merge << token
620
+ if token_index == group.length - 1 && group_index == groups.length - 1
621
+ new_tokens << wide_interval_merge.join(',')
622
+ end
623
+ else
624
+ new_tokens << token
598
625
  end
599
- elsif !to_merge.empty?
600
- new_tokens << to_merge.join(',')
601
- new_tokens << token
602
- to_merge = []
603
- else
604
- new_tokens << token
605
626
  end
606
627
  end
628
+
607
629
  new_tokens
608
630
  end
609
631
 
@@ -612,6 +634,18 @@ module OpeningHoursConverter
612
634
  values[0].to_i * 60 + values[1].to_i
613
635
  end
614
636
 
637
+ def is_part_of_wide_interval?(string)
638
+ is_wide_interval = false
639
+ string.split('-').each do |str|
640
+ if ((!(@RGX_YEAR =~ str).nil? || !(@RGX_YEAR_MONTH =~ str).nil? || !(@RGX_YEAR_MONTH_DAY =~ str).nil? || !(@RGX_DAY =~ str).nil? || !(@RGX_MONTHDAY =~ str).nil? || !(@RGX_MONTH =~ str).nil?) && ((@RGX_TIME =~ str).nil? && (@RGX_WEEKDAY =~ str).nil?))
641
+ is_wide_interval = true
642
+ else
643
+ return false
644
+ end
645
+ end
646
+ is_wide_interval
647
+ end
648
+
615
649
  def is_comment?(token)
616
650
  !(@RGX_COMMENT =~ token).nil?
617
651
  end
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.6.0
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziserman Martin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json