lib/torasup/operator.rb in torasup-0.0.5 vs lib/torasup/operator.rb in torasup-0.0.6
- old
+ new
@@ -16,30 +16,16 @@
end
interpolated_result
end
end
- def self.registered_prefixes
- Torasup.registered_prefixes
- end
-
def self.registered
- Torasup.registered_operators
+ build_metadata(:registered_operator_prefixes)
end
def self.all
- operators = {}
- Torasup.prefixes.each do |prefix, metadata|
- prefix_country_id = metadata["country_id"]
- country_operators = operators[prefix_country_id] ||= {}
- prefix_operator_id = metadata["id"]
- operator_metadata = country_operators[prefix_operator_id] ||= metadata.dup
- operator_metadata.delete("prefix")
- prefixes = operator_metadata["prefixes"] ||= []
- prefixes << prefix
- end
- operators
+ build_metadata(:prefixes)
end
private
def parse_phone_number(area_code_or_prefix, unresolved_local_number)
@@ -61,7 +47,23 @@
def full_prefix(*parts)
parts = [@area_code, @prefix] if parts.empty?
@country_code + parts.join
end
+
+ def self.build_metadata(operator_type)
+ operators = {}
+ Torasup.send(operator_type).each do |prefix, metadata|
+ prefix_country_id = metadata["country_id"]
+ country_operators = operators[prefix_country_id] ||= {}
+ prefix_operator_id = metadata["id"]
+ operator_metadata = country_operators[prefix_operator_id] ||= metadata.dup
+ operator_metadata.delete("prefix")
+ prefixes = operator_metadata["prefixes"] ||= []
+ prefixes << prefix
+ end
+ operators
+ end
+
+ private_class_method :build_metadata
end
end