Skip to content

Instantly share code, notes, and snippets.

@krazylegz
Forked from rivant/Base Notifier
Created November 17, 2015 14:58
Show Gist options
  • Select an option

  • Save krazylegz/bf6d91c7a2e9298fe356 to your computer and use it in GitHub Desktop.

Select an option

Save krazylegz/bf6d91c7a2e9298fe356 to your computer and use it in GitHub Desktop.
New:
class BaseNotifier
def initialize(attributes={})
@client_ip, @ec2_instance_id, @environment, @hl7_message,
@hl7_response, @queue_response, @stats, @title = %i(
client_ip ec2_instance_id environment hl7_message
hl7_response queue_response stats title
).map do |key|
attributes.fetch(key, '')
end
@pass = attributes.fetch(:pass, false)
end
Original:
class BaseNotifier
def initialize(data)
@client_ip = data.fetch(:client_ip, '')
@ec2_instance_id = data.fetch(:ec2_instance_id, '')
@environment = data.fetch(:environment, '')
@hl7_message = data.fetch(:hl7_message, '')
@hl7_response = data.fetch(:hl7_response, '')
@pass = data.fetch(:pass, false)
@queue_response = data.fetch(:queue_response, '')
@stats = data.fetch(:stats, '')
@title = data.fetch(:title, '')
end
end
Another option:
module HL7Engine
module Interfaces
module Labs2Go
# Base notification
class BaseNotifier
INSTANCE_VARIABLE_NAMES = %i(
client_ip ec2_instance_id environment hl7_message hl7_response
queue_response stats title
)
def initialize(attributes = {})
INSTANCE_VARIABLE_NAMES.each do |name|
instance_variable_set("@#{name}".to_sym, attributes.fetch(name, ''))
end
@pass = attributes.fetch(:pass, false)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment