lib/isic/isic.rb in isic-1.0.2 vs lib/isic/isic.rb in isic-1.0.3
- old
+ new
@@ -1,6 +1,6 @@
-module Isic
+class Isic
DIVISIONS = {}
DIVISIONS['A'] = %w( 01 02 03 )
DIVISIONS['B'] = %w( 05 06 07 08 09 )
DIVISIONS['C'] = %w( 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 )
@@ -39,27 +39,27 @@
[]
end
end
def groups(options = {})
- translation = options[:translation] || :en
- if options[:division] && /\d{2}/.match(options[:division])
- code = "#{options[:division]}\\d"
- Search.new(code, translation: translation).all
- else
- []
- end
+ parse(:division, 2, options)
end
def classes(options = {})
+ parse(:group, 3, options)
+ end
+
+ def parse(symbol, digits, options = {})
translation = options[:translation] || :en
- if options[:group] && /\d{3}/.match(options[:group])
- code = "#{options[:group]}\\d"
+ if options[symbol] && Regexp.new("\\d{#{digits}}").match(options[symbol])
+ code = "#{options[symbol]}\\d"
Search.new(code, translation: translation).all
else
[]
end
end
end
+
+ private_class_method :parse
end
\ No newline at end of file