Class: Holidays::Definition::Generator::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/definition/generator/module.rb

Instance Method Summary collapse

Instance Method Details

#call(module_name, files, regions, month_strings, custom_methods) ⇒ Object

Raises:

  • (ArgumentError)


7
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
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/holidays/definition/generator/module.rb', line 7

def call(module_name, files, regions, month_strings, custom_methods)
  raise ArgumentError.new("module name cannot be nil") if module_name.nil?
  raise ArgumentError.new("module name cannot be blank") if module_name.empty?

  raise ArgumentError.new("files cannot be nil") if files.nil?
  raise ArgumentError.new("files cannot be empty") if files.empty?
  raise ArgumentError.new("files must all be strings") unless files.all? { |f| f.is_a?(String) }

  raise ArgumentError.new("regions cannot be nil") if regions.nil?
  raise ArgumentError.new("regions cannot be empty") if regions.empty?

  raise ArgumentError.new("month strings cannot be nil") if month_strings.nil?
  raise ArgumentError.new("month strings cannot be empty") if month_strings.empty?

  module_src ="# encoding: utf-8\nmodule Holidays\n  # This file is generated by the Ruby Holidays gem.\n  #\n  # Definitions loaded: \#{files.join(', ')}\n  #\n  # All the definitions are available at https://github.com/holidays/holidays\n  module \#{module_name.to_s.upcase} # :nodoc:\n    def self.defined_regions\n      [:\#{regions.join(', :')}]\n    end\n\n    def self.holidays_by_month\n      {\n  \#{month_strings.join(\",\\n\")}\n      }\n    end\n\n    def self.custom_methods\n      {\n  \#{custom_methods}\n      }\n    end\n  end\nend\n  EOM\n\n  module_src\nend\n"