Sha256: 09f0c60c9d3973cbbcf7f6b9131f9590205ea4846462e903d9967cc367a2a25b
Contents?: true
Size: 697 Bytes
Versions: 1
Compression:
Stored size: 697 Bytes
Contents
# frozen_string_literal: true require 'date' module Rumanu def digit_sum(n) return 0 if n.zero? 1 + (n - 1) % 9 end def reduce_list(lst, alphabet) digit_sum(lst.map { |value| alphabet[value] }.compact.sum) end def valid_date?(str) valid_formats = [/\d{2}\.\d{2}\.\d{4}/, %r{\d{2}/\d{2}/\d{4}}, /\d{2}-\d{2}-\d{4}/, /\d{4}-\d{2}-\d{2}/] check_format = valid_formats.map { |f| f.match?(str) && 1 || 0 }.reduce(0, :+) raise ArgumentError, 'Incorrect date format' if check_format.zero? end def valid_hash?(h) raise ArgumentError, 'Object must me a Hash' unless h.is_a? Hash raise ArgumentError, 'Hash can not be empty' unless h.empty? true end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rumanu-0.15.0 | lib/rumanu/helpers.rb |