Sha256: 3492030d96ab42b28879bc33de56a8feba0657b0738fd38dfa91940d92f952cc

Contents?: true

Size: 689 Bytes

Versions: 2

Compression:

Stored size: 689 Bytes

Contents

require "polish_cell_number_checker/version"
require 'yaml'

module PolishCellNumber
  class Checker
    private
    def load_data
      @@data ||= YAML.load_file(File.join(File.dirname(__FILE__), '../yaml/operators.yml'))
    end

    def check_number
      @found = @phone_no =~ /[0-9]{9}/ ? @@data.select { |_, pool| pool.find { |e| @phone_no =~ /^#{e}/ } } : []
    end

    public
    def initialize(phone_no)
     @phone_no = phone_no.clone

      @phone_no.gsub!(/\D/, '')
      @phone_no.gsub!(/^48/, '')

      load_data
      check_number
    end

    def cell_number?
      !@found.empty?
    end

    def operator_name
      @found[0][0] unless @found.empty?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polish_cell_number_checker-0.0.6 lib/polish_cell_number_checker.rb
polish_cell_number_checker-0.0.5 lib/polish_cell_number_checker.rb