module Utils
Constants
- BASE
- BASE_INDICATOR
- DATA_LOOKUP_MIS
- PRIMARY
Public Instance Methods
blank?(obj)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/ez7gen/service/utils.rb, line 24 def get_segment_name(segment) return segment.gsub(/~|\[|\]|\{|\}/,"") end
get_type_by_name(name)
click to toggle source
if name starts with base use base type otherwise primary works for generators and parsers
# 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)
click to toggle source
check if string has special characters
# File lib/ez7gen/service/utils.rb, line 70 def has_html_encoded_ch?(str) (str =~ @@html_encoded_regex)?true:false end
is_number?(str)
click to toggle source
check if string is a number
# File lib/ez7gen/service/utils.rb, line 39 def is_number?(str) true if Float(str) rescue false end
num_to_nil(string)
click to toggle source
helper method to convert a string to nil if it's a number
# 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)
click to toggle source
helper method to safely handle max length when schema len adn requirements contradict. lesser wins
# 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)
click to toggle source
safely pick an index with collection
# File lib/ez7gen/service/utils.rb, line 33 def sample_index (len) # ... excludes the top of the range @@random.rand(0...len) end