Class: HealthcarePhony::Helper
- Inherits:
-
Object
- Object
- HealthcarePhony::Helper
- Defined in:
- lib/healthcare_phony/helper.rb
Class Method Summary collapse
- .double_alternate_digits(npi) ⇒ Object
- .get_array(input_argument) ⇒ Object
- .get_npi_check_digit(npi) ⇒ Object
- .next_number_end_with_zero(input) ⇒ Object
- .npi_step_one(input) ⇒ Object
- .npi_step_two(input, step_one_total) ⇒ Object
- .random_with_blank(non_blank_value, blank_percentage) ⇒ Object
Class Method Details
.double_alternate_digits(npi) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/healthcare_phony/helper.rb', line 48 def double_alternate_digits(npi) a_total = 0 counter = 1 npi.to_s.split('').each do |n| a_total += n.to_i if counter.even? counter += 1 end a_total end |
.get_array(input_argument) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/healthcare_phony/helper.rb', line 11 def get_array(input_argument) return_array = [] if !input_argument.nil? && input_argument.instance_of?(Array) return_array = input_argument elsif !input_argument.nil? && input_argument.instance_of?(String) return_array = input_argument.split(',') end return_array end |
.get_npi_check_digit(npi) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/healthcare_phony/helper.rb', line 58 def get_npi_check_digit(npi) step_one = npi_step_one(npi) # Add totals from above two steps + 24 # c_total = 24 + a_total + b_total step_two = npi_step_two(npi, step_one) next_high = next_number_end_with_zero(step_two) # Step 3: Subtract from next higher number ending in zero. (next_high - step_two) end |
.next_number_end_with_zero(input) ⇒ Object
43 44 45 46 |
# File 'lib/healthcare_phony/helper.rb', line 43 def next_number_end_with_zero(input) input += 1 while input.to_s[-1] != '0' input end |
.npi_step_one(input) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/healthcare_phony/helper.rb', line 23 def npi_step_one(input) # Step 1: Double the value of alternate digits, beginning with the rightmost digit. npi = [] input.to_s.split('').reverse.each_with_index do |n, i| npi.push((n.to_i * 2).to_s) if (i + 1).odd? end npi.reverse! total = 0 npi.join('').split('').each do |x| total += x.to_i end total end |
.npi_step_two(input, step_one_total) ⇒ Object
37 38 39 40 41 |
# File 'lib/healthcare_phony/helper.rb', line 37 def npi_step_two(input, step_one_total) # Step 2: Add constant 24, to account for the 80840 prefix that would be present on a card issuer identifier, # plus the individual digits of products of doubling, plus unaffected digits. (24 + step_one_total + double_alternate_digits(input)) end |
.random_with_blank(non_blank_value, blank_percentage) ⇒ Object
6 7 8 9 |
# File 'lib/healthcare_phony/helper.rb', line 6 def random_with_blank(non_blank_value, blank_percentage) b_array = [[non_blank_value, (100 - blank_percentage)], ['', blank_percentage]] b_array.max_by { |_, weight| rand**100.fdiv(weight) }[0] end |