Skip to content

Instantly share code, notes, and snippets.

@SViccari
Last active June 22, 2020 18:11
Show Gist options
  • Save SViccari/141349ee5ee63f1071504f556b0832c3 to your computer and use it in GitHub Desktop.
Save SViccari/141349ee5ee63f1071504f556b0832c3 to your computer and use it in GitHub Desktop.
NDC ID Formatter
# revise the MedicationReconciliationCreator class
# to use the newly introduced NdcIdFormatter
class MedicationReconciliationCreator
# existing code to build a reconciled medication
def formatted_ndc_id(ndc_id)
NdcIdFormatter.format(ndc_id)
end
end
# For test coverage for this class, I would
# only test the happy path and not stub out
# the call to the NdcIdFormatter.
class NdcIdFormatter
def self.format(ndc_id)
new(ndc_id).format
end
def initialize(ndc_id)
@ndc_id = ndc_id
end
def format
# ... code that adds necessary padding ...
end
private
att_reader :ndc_id
end
RSpec.describe NdcIdFormatter do
describe ".format" do
it "removes all hyphens" do
end
it "returns nil for empty values" do
expect(NdcIdFormatter.format("").to be nil
expect(NdcIdFormatter.format(nil).to be nil
end
context "given an ID in the 4-4-2 format" do
it "adds a leading zero to first section" do
ndc_id = "0777-3105-02"
NdcIdFormatter.format(ndc_id).to eq("00777310502")
end
end
context "given an ID in the 5-3-2 format" do
it "adds a leading zero to the middle section" do
end
end
context "given an ID in the 5-4-1 format" do
it "adds a leading zero to the last section" do
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment