Class: MobME::Infrastructure::Utilities::FileOperations::MSISDNFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/mobme_support/file/msisdn_filter.rb

Overview

Filters for MSISDN-s in files.

Class Method Summary collapse

Class Method Details

.filter(file_path, options_hash = {}) ⇒ Array

Filters input file for valid MSISDN-s.

Examples:

MSISDN filtration on a file.

MobME::Infrastructure::Utilities::FileOperations::MSISDNFilter.filter('/absolute/path/to/file')
>> ["9876543210", "9876543211", "9876543212", ... ]
MobME::Infrastructure::Utilities::FileOperations::MSISDNFilter.filter('/absolute/path/to/file', :format => "plus_country")
>> ["+919876543210", "+919876543211", "+919876543212", ... ]

Parameters:

  • file_path (String)

    Path to file containing line-separated MSISDN-s.

  • options_hash (Hash) (defaults to: {})

    Options with which to evaluate MSISDN-s.

Options Hash (options_hash):

  • :country (String) — default: 'IN'

    The ISO 3166 code for the MSISDN’s country.

  • :format (String) — default: 'local'

    Either ‘local’, ‘international’, ‘country’, ‘plus_country’.

Returns:

  • (Array)

    Array of valid MSISDN-s in requested format.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mobme_support/file/msisdn_filter.rb', line 22

def filter(file_path, options_hash={})
  options_hash.recursively_symbolize_keys!
  options_hash.reverse_merge!({
    :country => "IN",
    :format => "local"
  })

  input_file_contents = get_file_contents(file_path)
  input_file_contents.scan(pattern(options_hash)).map do |match|
    case options_hash[:format]
      when "local"
        match[2]
      when "country"
        settings[options_hash[:country]]['country_code'] + match[2]
      when "plus_country"
        "+#{settings[options_hash[:country]]['country_code']}#{match[2]}"
      when "international"
        settings[options_hash[:country]]['international_prefix'] + settings[options_hash[:country]]['country_code'] + match[2]
      else
        raise "Invalid :format value - must be one of 'local', 'country', 'plus_country', or 'international'."
    end

  end
end