Class: Holidays::Definition::Context::Generator
- Inherits:
-
Object
- Object
- Holidays::Definition::Context::Generator
- Defined in:
- lib/holidays/definition/context/generator.rb
Instance Method Summary collapse
- #generate_definition_source(module_name, files, regions, rules_by_month, custom_methods, tests) ⇒ Object
- #parse_definition_files(files) ⇒ Object
Instance Method Details
#generate_definition_source(module_name, files, regions, rules_by_month, custom_methods, tests) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/holidays/definition/context/generator.rb', line 41 def generate_definition_source(module_name, files, regions, rules_by_month, custom_methods, tests) month_strings = generate_month_definition_strings(rules_by_month) # Build the custom methods string custom_method_string = '' custom_methods.each do |key, code| custom_method_string << code + "\n\n" end module_src = generate_module_src(module_name, files, regions, month_strings, custom_method_string) test_src = generate_test_src(module_name, files, tests) return module_src, test_src || '' end |
#parse_definition_files(files) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/holidays/definition/context/generator.rb', line 8 def parse_definition_files(files) raise ArgumentError, "Must have at least one file to parse" if files.nil? || files.empty? all_regions = [] all_rules_by_month = {} all_custom_methods = {} all_tests = [] files.flatten! files.each do |file| definition_file = YAML.load_file(file) regions, rules_by_month = parse_month_definitions(definition_file['months']) all_regions << regions.flatten all_rules_by_month.merge!(rules_by_month) { |month, existing, new| existing << new existing.flatten! } custom_methods = parse_method_definitions(definition_file['methods']) all_custom_methods.merge!(custom_methods) all_tests << parse_test_definitions(definition_file['tests']) end all_regions.flatten!.uniq! [all_regions, all_rules_by_month, all_custom_methods, all_tests] end |