Class: Holidays::Definition::Parser::CustomMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/definition/parser/custom_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(validator) ⇒ CustomMethod

Returns a new instance of CustomMethod.



7
8
9
# File 'lib/holidays/definition/parser/custom_method.rb', line 7

def initialize(validator)
  @validator = validator
end

Instance Method Details

#call(methods) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/holidays/definition/parser/custom_method.rb', line 11

def call(methods)
  return {} if methods.nil? || methods.empty?

  validate!(methods)

  custom_methods = {}

  methods.each do |name, pieces|
    arguments = parse_arguments!(pieces["arguments"])

    custom_methods[method_key(name, arguments)] = Entity::CustomMethod.new({
      name: name,
      arguments: arguments,
      source: pieces["source"],
    })
  end

  custom_methods
end