holidays 4.6.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/CONTRIBUTING.md +5 -5
  4. data/Makefile +29 -0
  5. data/README.md +13 -1
  6. data/Rakefile +2 -2
  7. data/definitions/au.yaml +12 -9
  8. data/definitions/ca.yaml +17 -2
  9. data/definitions/ch.yaml +1 -1
  10. data/definitions/index.yaml +3 -0
  11. data/definitions/is.yaml +1 -1
  12. data/definitions/jp.yaml +19 -14
  13. data/definitions/kr.yaml +282 -0
  14. data/definitions/lu.yaml +56 -0
  15. data/definitions/my.yaml +51 -0
  16. data/definitions/ups.yaml +1 -1
  17. data/definitions/us.yaml +1 -1
  18. data/lib/generated_definitions/MANIFEST +3 -0
  19. data/lib/generated_definitions/REGIONS.rb +1 -1
  20. data/lib/generated_definitions/au.rb +11 -8
  21. data/lib/generated_definitions/ca.rb +1 -1
  22. data/lib/generated_definitions/ch.rb +1 -1
  23. data/lib/generated_definitions/europe.rb +2 -2
  24. data/lib/generated_definitions/is.rb +1 -1
  25. data/lib/generated_definitions/jp.rb +13 -15
  26. data/lib/generated_definitions/kr.rb +248 -0
  27. data/lib/generated_definitions/lu.rb +39 -0
  28. data/lib/generated_definitions/my.rb +36 -0
  29. data/lib/generated_definitions/north_america.rb +2 -2
  30. data/lib/generated_definitions/scandinavia.rb +1 -1
  31. data/lib/generated_definitions/ups.rb +1 -1
  32. data/lib/generated_definitions/us.rb +1 -1
  33. data/lib/holidays.rb +29 -51
  34. data/lib/holidays/core_extensions/date.rb +1 -1
  35. data/lib/holidays/definition/context/function_processor.rb +86 -0
  36. data/lib/holidays/definition/context/generator.rb +31 -6
  37. data/lib/holidays/definition/parser/custom_method.rb +1 -3
  38. data/lib/holidays/definition/repository/holidays_by_month.rb +1 -1
  39. data/lib/holidays/definition/validator/region.rb +1 -3
  40. data/lib/holidays/errors.rb +1 -0
  41. data/lib/holidays/factory/date_calculator.rb +37 -0
  42. data/lib/holidays/factory/definition.rb +96 -0
  43. data/lib/holidays/factory/finder.rb +70 -0
  44. data/lib/holidays/finder/context/between.rb +43 -0
  45. data/lib/holidays/{use_case → finder}/context/dates_driver_builder.rb +6 -4
  46. data/lib/holidays/finder/context/next_holiday.rb +57 -0
  47. data/lib/holidays/{option → finder}/context/parse_options.rb +6 -8
  48. data/lib/holidays/finder/context/search.rb +86 -0
  49. data/lib/holidays/finder/context/year_holiday.rb +57 -0
  50. data/lib/holidays/finder/rules/in_region.rb +23 -0
  51. data/lib/holidays/finder/rules/year_range.rb +82 -0
  52. data/lib/holidays/load_all_definitions.rb +7 -5
  53. data/lib/holidays/version.rb +1 -1
  54. data/test/coverage_report.rb +7 -0
  55. data/test/defs/test_defs_au.rb +1 -1
  56. data/test/defs/test_defs_ca.rb +16 -1
  57. data/test/defs/test_defs_jp.rb +4 -0
  58. data/test/defs/test_defs_kr.rb +26 -0
  59. data/test/defs/test_defs_lu.rb +24 -0
  60. data/test/defs/test_defs_my.rb +20 -0
  61. data/test/defs/test_defs_north_america.rb +16 -1
  62. data/test/holidays/core_extensions/test_date_time.rb +7 -7
  63. data/test/holidays/definition/context/test_function_processor.rb +175 -0
  64. data/test/holidays/definition/context/test_generator.rb +18 -11
  65. data/test/holidays/definition/parser/test_custom_method.rb +2 -2
  66. data/test/holidays/definition/repository/test_proc_result_cache.rb +1 -1
  67. data/test/holidays/{test_date_calculator_factory.rb → factory/test_date_calculator.rb} +3 -3
  68. data/test/holidays/factory/test_definition.rb +53 -0
  69. data/test/holidays/factory/test_finder.rb +25 -0
  70. data/test/holidays/finder/context/test_between.rb +172 -0
  71. data/test/holidays/{use_case → finder}/context/test_dates_driver_builder.rb +2 -2
  72. data/test/holidays/finder/context/test_next_holiday.rb +156 -0
  73. data/test/holidays/{option → finder}/context/test_parse_options.rb +9 -9
  74. data/test/holidays/finder/context/test_search.rb +203 -0
  75. data/test/holidays/finder/context/test_year_holiday.rb +202 -0
  76. data/test/holidays/finder/rules/test_in_region.rb +38 -0
  77. data/test/holidays/finder/rules/test_year_range.rb +170 -0
  78. data/test/integration/README.md +9 -0
  79. data/test/{test_all_regions.rb → integration/test_all_regions.rb} +16 -2
  80. data/test/{test_custom_holidays.rb → integration/test_custom_holidays.rb} +2 -2
  81. data/test/{test_custom_year_range_holidays.rb → integration/test_custom_year_range_holidays.rb} +1 -1
  82. data/test/{test_holidays.rb → integration/test_holidays.rb} +43 -32
  83. data/test/{test_holidays_between.rb → integration/test_holidays_between.rb} +8 -16
  84. data/test/{test_multiple_regions.rb → integration/test_multiple_regions.rb} +1 -1
  85. data/test/test_helper.rb +3 -4
  86. metadata +67 -39
  87. data/benchmark.rb +0 -8
  88. data/lib/holidays/date_calculator_factory.rb +0 -35
  89. data/lib/holidays/definition_factory.rb +0 -86
  90. data/lib/holidays/option_factory.rb +0 -15
  91. data/lib/holidays/use_case/context/between.rb +0 -45
  92. data/lib/holidays/use_case/context/context_common.rb +0 -123
  93. data/lib/holidays/use_case/context/next_holiday.rb +0 -54
  94. data/lib/holidays/use_case/context/year_holiday.rb +0 -51
  95. data/lib/holidays/use_case_factory.rb +0 -41
  96. data/test/holidays/test_definition_factory.rb +0 -49
  97. data/test/holidays/test_option_factory.rb +0 -9
  98. data/test/holidays/test_use_case_factory.rb +0 -13
  99. data/test/holidays/use_case/context/test_between.rb +0 -77
@@ -1,54 +0,0 @@
1
- module Holidays
2
- module UseCase
3
- module Context
4
- class NextHoliday
5
- include ContextCommon
6
-
7
- def initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo)
8
- @holidays_by_month_repo = holidays_by_month_repo
9
- @day_of_month_calculator = day_of_month_calculator
10
- @custom_methods_repo = custom_methods_repo
11
- @proc_result_cache_repo = proc_result_cache_repo
12
- end
13
-
14
- def call(holidays_count, from_date, dates_driver, regions, observed, informal)
15
- validate!(holidays_count, from_date, dates_driver, regions)
16
- holidays = []
17
- ret_holidays = []
18
-
19
- ret_holidays = make_date_array(dates_driver, regions, observed, informal)
20
- ret_holidays.each do |holiday|
21
- if holiday[:date] >= from_date
22
- holidays << holiday
23
- holidays_count -= 1
24
- break if holidays_count == 0
25
- end
26
- end
27
-
28
- holidays.sort{|a, b| a[:date] <=> b[:date] }
29
- end
30
-
31
- private
32
-
33
- attr_reader :holidays_by_month_repo,
34
- :day_of_month_calculator,
35
- :custom_methods_repo,
36
- :proc_result_cache_repo
37
-
38
- def validate!(holidays_count, from_date, dates_driver, regions)
39
- raise ArgumentError unless holidays_count
40
- raise ArgumentError if holidays_count <= 0
41
- raise ArgumentError unless from_date
42
-
43
- raise ArgumentError if dates_driver.nil? || dates_driver.empty?
44
-
45
- dates_driver.each do |year, months|
46
- raise ArgumentError if months.nil? || months.empty?
47
- end
48
-
49
- raise ArgumentError if regions.nil? || regions.empty?
50
- end
51
- end
52
- end
53
- end
54
- end
@@ -1,51 +0,0 @@
1
- module Holidays
2
- module UseCase
3
- module Context
4
- class YearHoliday
5
- include ContextCommon
6
-
7
- def initialize(holidays_by_month_repo, day_of_month_calculator, custom_methods_repo, proc_result_cache_repo)
8
- @holidays_by_month_repo = holidays_by_month_repo
9
- @day_of_month_calculator = day_of_month_calculator
10
- @custom_methods_repo = custom_methods_repo
11
- @proc_result_cache_repo = proc_result_cache_repo
12
- end
13
-
14
- def call(from_date, to_date, dates_driver, regions, observed, informal)
15
- validate!(from_date, to_date, dates_driver, regions)
16
- holidays = []
17
- ret_holidays = []
18
-
19
- ret_holidays = make_date_array(dates_driver, regions, observed, informal)
20
- ret_holidays.each do |holiday|
21
- if holiday[:date] >= from_date && holiday[:date] <= to_date
22
- holidays << holiday
23
- end
24
- end
25
-
26
- holidays.sort{|a, b| a[:date] <=> b[:date] }
27
- end
28
-
29
- private
30
-
31
- attr_reader :holidays_by_month_repo,
32
- :day_of_month_calculator,
33
- :custom_methods_repo,
34
- :proc_result_cache_repo
35
-
36
- def validate!(from_date, to_date, dates_driver, regions)
37
- raise ArgumentError unless from_date
38
- raise ArgumentError unless to_date
39
-
40
- raise ArgumentError if dates_driver.nil? || dates_driver.empty?
41
-
42
- dates_driver.each do |year, months|
43
- raise ArgumentError if months.nil? || months.empty?
44
- end
45
-
46
- raise ArgumentError if regions.nil? || regions.empty?
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,41 +0,0 @@
1
- require 'holidays/use_case/context/context_common'
2
- require 'holidays/use_case/context/between'
3
- require 'holidays/use_case/context/next_holiday'
4
- require 'holidays/use_case/context/dates_driver_builder'
5
- require 'holidays/use_case/context/year_holiday'
6
-
7
- module Holidays
8
- class UseCaseFactory
9
- class << self
10
- def between
11
- UseCase::Context::Between.new(
12
- DefinitionFactory.holidays_by_month_repository,
13
- DateCalculatorFactory.day_of_month_calculator,
14
- DefinitionFactory.custom_methods_repository,
15
- DefinitionFactory.proc_result_cache_repository,
16
- )
17
- end
18
- def next_holiday
19
- UseCase::Context::NextHoliday.new(
20
- DefinitionFactory.holidays_by_month_repository,
21
- DateCalculatorFactory.day_of_month_calculator,
22
- DefinitionFactory.custom_methods_repository,
23
- DefinitionFactory.proc_result_cache_repository,
24
- )
25
- end
26
-
27
- def year_holiday
28
- UseCase::Context::YearHoliday.new(
29
- DefinitionFactory.holidays_by_month_repository,
30
- DateCalculatorFactory.day_of_month_calculator,
31
- DefinitionFactory.custom_methods_repository,
32
- DefinitionFactory.proc_result_cache_repository,
33
- )
34
- end
35
-
36
- def dates_driver_builder
37
- UseCase::Context::DatesDriverBuilder.new
38
- end
39
- end
40
- end
41
- end
@@ -1,49 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- require 'holidays/definition_factory'
4
-
5
- class DefinitionFactoryTests < Test::Unit::TestCase
6
- def test_definition_file_parser
7
- assert Holidays::DefinitionFactory.file_parser.is_a?(Holidays::Definition::Context::Generator)
8
- end
9
-
10
- def test_definition_source_generator
11
- assert Holidays::DefinitionFactory.source_generator.is_a?(Holidays::Definition::Context::Generator)
12
- end
13
-
14
- def test_definition_merger
15
- assert Holidays::DefinitionFactory.merger.is_a?(Holidays::Definition::Context::Merger)
16
- end
17
-
18
- def test_holidays_by_month_repository
19
- assert Holidays::DefinitionFactory.holidays_by_month_repository.is_a?(Holidays::Definition::Repository::HolidaysByMonth)
20
- end
21
-
22
- def test_regions_repository
23
- assert Holidays::DefinitionFactory.regions_repository.is_a?(Holidays::Definition::Repository::Regions)
24
- end
25
-
26
- def test_cache_repository
27
- assert Holidays::DefinitionFactory.cache_repository.is_a?(Holidays::Definition::Repository::Cache)
28
- end
29
-
30
- def test_proc_result_cache_repository
31
- assert Holidays::DefinitionFactory.proc_result_cache_repository.is_a?(Holidays::Definition::Repository::ProcResultCache)
32
- end
33
-
34
- def test_custom_method_parser
35
- assert Holidays::DefinitionFactory.custom_method_parser.is_a?(Holidays::Definition::Parser::CustomMethod)
36
- end
37
-
38
- def test_custom_method_source_decorator
39
- assert Holidays::DefinitionFactory.custom_method_source_decorator.is_a?(Holidays::Definition::Decorator::CustomMethodSource)
40
- end
41
-
42
- def test_custom_method_validator
43
- assert Holidays::DefinitionFactory.custom_method_validator.is_a?(Holidays::Definition::Validator::CustomMethod)
44
- end
45
-
46
- def test_region_validator
47
- assert Holidays::DefinitionFactory.region_validator.is_a?(Holidays::Definition::Validator::Region)
48
- end
49
- end
@@ -1,9 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- require 'holidays/option_factory'
4
-
5
- class OptionFactoryTests < Test::Unit::TestCase
6
- def test_parse_options_factory
7
- assert Holidays::OptionFactory.parse_options.is_a?(Holidays::Option::Context::ParseOptions)
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../test_helper'
2
-
3
- require 'holidays/use_case_factory'
4
-
5
- class UseCaseFactoryTests < Test::Unit::TestCase
6
- def test_between_factory
7
- assert Holidays::UseCaseFactory.between.is_a?(Holidays::UseCase::Context::Between)
8
- end
9
-
10
- def test_dates_driver_builder_factory
11
- assert Holidays::UseCaseFactory.dates_driver_builder.is_a?(Holidays::UseCase::Context::DatesDriverBuilder)
12
- end
13
- end
@@ -1,77 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__)) + '/../../../test_helper'
2
-
3
- require 'holidays/use_case/context/between'
4
-
5
- #TODO These tests need love. This is the heart of the holiday logic and I'm only
6
- # now starting to tear bits and pieces of it apart to untangle it. This is a start
7
- # but definitely needs more coverage.
8
- class BetweenTests < Test::Unit::TestCase
9
- def setup
10
- @holidays_by_month_repo = mock()
11
- @day_of_month_calculator = mock()
12
- @custom_method_repo = mock()
13
- @proc_cache_repo = mock()
14
-
15
- @subject = Holidays::UseCase::Context::Between.new(
16
- @holidays_by_month_repo,
17
- @day_of_month_calculator,
18
- @custom_method_repo,
19
- @proc_cache_repo,
20
- )
21
-
22
- @start_date = Date.civil(2015, 1, 1)
23
- @end_date = Date.civil(2015, 1, 1)
24
- @dates_driver = {2015 => [0, 1, 2], 2014 => [0, 12]}
25
- @regions = [:us]
26
- @observed = false
27
- @informal = false
28
- end
29
-
30
- def test_returns_error_if_start_date_is_missing
31
- assert_raise ArgumentError do
32
- @subject.call(nil, @end_date, @dates_driver, @regions, @observed, @informal)
33
- end
34
- end
35
-
36
- def test_returns_error_if_end_date_is_missing
37
- assert_raise ArgumentError do
38
- @subject.call(@start_date, nil, @dates_driver, @regions, @observed, @informal)
39
- end
40
- end
41
-
42
- def test_returns_error_if_driver_hash_is_nil
43
- assert_raise ArgumentError do
44
- @subject.call(@start_date, @end_date, nil, @regions, @observed, @informal)
45
- end
46
- end
47
-
48
- def test_returns_error_if_driver_hash_is_empty
49
- assert_raise ArgumentError do
50
- @subject.call(@start_date, @end_date, {}, @regions, @observed, @informal)
51
- end
52
- end
53
-
54
- def test_returns_error_if_driver_hash_has_empty_months_array
55
- assert_raise ArgumentError do
56
- @subject.call(@start_date, @end_date, {2015 => nil}, @regions, @observed, @informal)
57
- end
58
-
59
- assert_raise ArgumentError do
60
- @subject.call(@start_date, @end_date, {2015 => []}, @regions, @observed, @informal)
61
- end
62
-
63
- assert_raise ArgumentError do
64
- @subject.call(@start_date, @end_Date, {2015 => [1], 2016 => [1], 2017 => []}, @regions, @observed, @informal)
65
- end
66
- end
67
-
68
- def test_returns_error_if_regions_are_missing_or_empty
69
- assert_raise ArgumentError do
70
- @subject.call(@start_date, @end_date, @dates_driver, nil, @observed, @informal)
71
- end
72
-
73
- assert_raise ArgumentError do
74
- @subject.call(@start_date, @end_date, @dates_driver, [], @observed, @informal)
75
- end
76
- end
77
- end