Module: Utils
- Included in:
- BaseFieldGenerator, DynamicFieldGenerator, FieldGenerator, Group, MessageFactory, ProfileParser, SegmentGenerator, SegmentPicker, StructureParser, TemplateGenerator, TypeAwareFieldGenerator
- Defined in:
- lib/ez7gen/service/utils.rb
Constant Summary collapse
- BASE_INDICATOR =
'base:'
- BASE =
'base'
- PRIMARY =
'primary'
- DATA_LOOKUP_MIS =
{:position => '1', :value => '...', :description => 'No suggested values defined'}
- @@random =
Random.new
- @@special =
special = “?<>‘,?[]}Utils.=-)(*&^%$=-)(*&^%$#`~{” @@special = “?<>[]}Utils.)(&^%$)(&^%$#`~{” # subset to use for now
"&"
- @@html_encoded_regex =
it looks like only html encoded characters are problem, ex: Pathology (gross & histopath, not surgical) tbl 74
/[#{@@special.gsub(/./){|char| "\\#{char}"}}]/
Instance Method Summary collapse
- #blank?(obj) ⇒ Boolean
- #get_name_without_base(name) ⇒ Object
- #get_segment_name(segment) ⇒ Object
-
#get_type_by_name(name) ⇒ Object
if name starts with base use base type otherwise primary works for generators and parsers.
-
#has_html_encoded_ch?(str) ⇒ Boolean
check if string has special characters.
-
#is_number?(str) ⇒ Boolean
check if string is a number.
-
#num_to_nil(string) ⇒ Object
helper method to convert a string to nil if it’s a number.
-
#safe_len(maxLen, reqLen) ⇒ Object
helper method to safely handle max length when schema len adn requirements contradict.
-
#sample_index(len) ⇒ Object
safely pick an index with collection.
Instance Method Details
#blank?(obj) ⇒ Boolean
28 29 30 |
# File 'lib/ez7gen/service/utils.rb', line 28 def blank?(obj) return obj.nil? || obj.empty? #|| obj.strip.empty? end |
#get_name_without_base(name) ⇒ Object
49 50 51 |
# File 'lib/ez7gen/service/utils.rb', line 49 def get_name_without_base(name) (!blank?(name))?name.delete(BASE_INDICATOR):nil end |
#get_segment_name(segment) ⇒ Object
24 25 26 |
# File 'lib/ez7gen/service/utils.rb', line 24 def get_segment_name(segment) return segment.gsub(/~|\[|\]|\{|\}/,"") end |
#get_type_by_name(name) ⇒ Object
if name starts with base use base type otherwise primary works for generators and parsers
45 46 47 |
# File 'lib/ez7gen/service/utils.rb', line 45 def get_type_by_name(name) (blank?(name)?nil:(name.include?(BASE_INDICATOR))? BASE: PRIMARY) end |
#has_html_encoded_ch?(str) ⇒ Boolean
check if string has special characters
70 71 72 |
# File 'lib/ez7gen/service/utils.rb', line 70 def has_html_encoded_ch?(str) (str =~ @@html_encoded_regex)?true:false end |
#is_number?(str) ⇒ Boolean
check if string is a number
39 40 41 |
# File 'lib/ez7gen/service/utils.rb', line 39 def is_number?(str) true if Float(str) rescue false end |
#num_to_nil(string) ⇒ Object
helper method to convert a string to nil if it’s a number
54 55 56 57 58 59 |
# File 'lib/ez7gen/service/utils.rb', line 54 def num_to_nil(string) Integer(string || '') return nil rescue ArgumentError return string end |
#safe_len(maxLen, reqLen) ⇒ Object
helper method to safely handle max length when schema len adn requirements contradict. lesser wins
63 64 65 66 67 |
# File 'lib/ez7gen/service/utils.rb', line 63 def safe_len(maxLen, reqLen) #handle stings and garbage maxLen = (maxLen||reqLen).to_i [maxLen, reqLen].min end |
#sample_index(len) ⇒ Object
safely pick an index with collection
33 34 35 36 |
# File 'lib/ez7gen/service/utils.rb', line 33 def sample_index (len) # ... excludes the top of the range @@random.rand(0...len) end |