D
dkmd_nielsen
I have a base class into which I'm coding a number of my companies
standard business rules into. This class is used time and time again
amongs all the other processing classes. There are multiple fields
that have a static number of values. For example, something called the
house/rental indicator can only have values of H|R|P|F|S|<blank>.
The first suggestion I'm seeking is how to properly code for those
values. I've started by coding the following constants, followed by
the validation routine. I would like the individual values available
for testing (IF X=House, etal...), but I also wanted all of them in a
group so the field presented can tested in one function (.index). What
do you suggest?
# List type acceptable values
House = 'H' # House list indicator
Rental = 'R' # Rental list indicator
Purge = 'P' # Purge list indicator
Flag = 'F' # Flag list indicator
Seed = 'S' # Seed list indicator
ValidHrInd = Flag+House+Purge+Rental+Seed
def Standards.valid_hrind?(id)
return true if (id.length == 1 && ValidHrInd.index(id))
false
end
On the heels of that is the second recommendation I am seeking. This
standards class is used over and over again. I was hoping that I could
code the require 'standards.rb' into each class that will require it.
This way, if I have a module that needs multiple classes and some of
them (or all of them) require the standards.rb, then the classes have
taken care of their own requirements. But with the constants coded in
standards.rb, I get warning messages that the constants are being
reassigned for each require 'standards.rb'. What is the best way to
have a class define its own requirements?
== module DataCard.rb ==
require 'standards.rb'
class DataCard
....
end
== module Project.rb ==
require 'standards.rb'
class Project
....
end
Thanks for your time and advice,
dvn
standard business rules into. This class is used time and time again
amongs all the other processing classes. There are multiple fields
that have a static number of values. For example, something called the
house/rental indicator can only have values of H|R|P|F|S|<blank>.
The first suggestion I'm seeking is how to properly code for those
values. I've started by coding the following constants, followed by
the validation routine. I would like the individual values available
for testing (IF X=House, etal...), but I also wanted all of them in a
group so the field presented can tested in one function (.index). What
do you suggest?
# List type acceptable values
House = 'H' # House list indicator
Rental = 'R' # Rental list indicator
Purge = 'P' # Purge list indicator
Flag = 'F' # Flag list indicator
Seed = 'S' # Seed list indicator
ValidHrInd = Flag+House+Purge+Rental+Seed
def Standards.valid_hrind?(id)
return true if (id.length == 1 && ValidHrInd.index(id))
false
end
On the heels of that is the second recommendation I am seeking. This
standards class is used over and over again. I was hoping that I could
code the require 'standards.rb' into each class that will require it.
This way, if I have a module that needs multiple classes and some of
them (or all of them) require the standards.rb, then the classes have
taken care of their own requirements. But with the constants coded in
standards.rb, I get warning messages that the constants are being
reassigned for each require 'standards.rb'. What is the best way to
have a class define its own requirements?
== module DataCard.rb ==
require 'standards.rb'
class DataCard
....
end
== module Project.rb ==
require 'standards.rb'
class Project
....
end
Thanks for your time and advice,
dvn