class Holidays::Definition::Parser::CustomMethod
Public Class Methods
new(validator)
click to toggle source
# File lib/holidays/definition/parser/custom_method.rb, line 7 def initialize(validator) @validator = validator end
Public Instance Methods
call(methods)
click to toggle source
# 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["ruby"], }) end custom_methods end
Private Instance Methods
args_string(args)
click to toggle source
# File lib/holidays/definition/parser/custom_method.rb, line 60 def args_string(args) a = args.join(", ") a[0..-1] end
method_key(name, args)
click to toggle source
# File lib/holidays/definition/parser/custom_method.rb, line 56 def method_key(name, args) "#{name.to_s}(#{args_string(args)})" end
parse_arguments!(arguments)
click to toggle source
# File lib/holidays/definition/parser/custom_method.rb, line 45 def parse_arguments!(arguments) splitArgs = arguments.split(",") parsedArgs = [] splitArgs.each do |arg| parsedArgs << arg.strip end parsedArgs end
validate!(methods)
click to toggle source
# File lib/holidays/definition/parser/custom_method.rb, line 33 def validate!(methods) raise ArgumentError unless methods.all? do |name, pieces| @validator.valid?( { :name => name, :arguments => pieces["arguments"], :source => pieces["ruby"] } ) end end