Module: VatInfo::Utils

Defined in:
lib/vat_info/utils.rb

Constant Summary collapse

COMPANY_TYPES =
['a.s.', 's.r.o.', 'v.o.s.', 'k.s.', 'z.s.'].freeze
SPECIAL_CHARS =
[
  %w(Á á), %w(Č č), %w(Ď ď), %w(É é), %w(Ě ě), %w(Í í), %w(Ň ń), %w(Ó ó),
  %w(Ř ř), %w(Š š), %w(Ť ť), %w(Ú ú), %w(Ů ů), %w(Ž ž), %w(Ý ý)
].freeze

Class Method Summary collapse

Class Method Details

.format_this(string) ⇒ Object



32
33
34
35
36
# File 'lib/vat_info/utils.rb', line 32

def self.format_this(string)
  return string.downcase if string.size == 1
  return string.downcase if COMPANY_TYPES.include? string.downcase
  replace_special_chars(string.capitalize)
end

.normalize(string) ⇒ Object



13
14
15
16
17
18
# File 'lib/vat_info/utils.rb', line 13

def self.normalize(string)
  return unless string
  replace_exceptions(string).strip.split(' ').map do |word|
    format_this word
  end.join(' ')
end

.replace_exceptions(string) ⇒ Object



28
29
30
# File 'lib/vat_info/utils.rb', line 28

def self.replace_exceptions(string)
  string.gsub(/,.+spol\.+ s r.o./i, ' s.r.o.')
end

.replace_special_chars(string) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/vat_info/utils.rb', line 20

def self.replace_special_chars(string)
  sub_string = string[1..-1]
  SPECIAL_CHARS.each do |pattern|
    sub_string = sub_string.gsub(/#{pattern[0]}/i, pattern[1])
  end
  string[0].concat(sub_string)
end

.wrap_in_array(content) ⇒ Object



9
10
11
# File 'lib/vat_info/utils.rb', line 9

def self.wrap_in_array(content)
  content.is_a?(Array) ? content : [content]
end