lib/credy/rules.rb in credy-0.2.0 vs lib/credy/rules.rb in credy-0.2.1
- old
+ new
@@ -1,18 +1,18 @@
require 'yaml'
module Credy
+ module Rules
+ extend self
- class Rules
-
# Return all the rules from yml files
- def self.raw
+ def raw
@rules ||= load_rules("#{Credy.root}/data/*.yml")
end
# Change hash format to process rules
- def self.all
+ def all
rules = []
raw.each do |type, details|
# Add general rules
Array(details['prefix']).each do |prefix|
@@ -41,26 +41,25 @@
# Sort by prefix length
rules.sort { |x, y| y[:prefix].length <=> x[:prefix].length }
end
# Returns rules according to given filters
- def self.filter(filters = {})
+ def filter(filters = {})
all.select do |rule|
[:country, :type].each do |condition|
break false if filters[condition] && filters[condition] != rule[condition]
true
end
end
end
- def self.load_rules(files)
+ private
+
+ def load_rules(files)
{}.tap do |rules|
Dir.glob(files) do |filename|
rules.merge! YAML::load IO.read(filename)
end
end
end
- private_class_method :load_rules
-
end
-
end