class ItaxCode::Utils

Public Instance Methods

cin_evens() click to toggle source
# File lib/itax_code/utils.rb, line 39
def cin_evens
  {
    "0": 0,  "1": 1,  "2": 2,  "3": 3,  "4": 4,  "5": 5,
    "6": 6,  "7": 7,  "8": 8,  "9": 9,  "A": 0,  "B": 1,
    "C": 2,  "D": 3,  "E": 4,  "F": 5,  "G": 6,  "H": 7,
    "I": 8,  "J": 9,  "K": 10, "L": 11, "M": 12, "N": 13,
    "O": 14, "P": 15, "Q": 16, "R": 17, "S": 18, "T": 19,
    "U": 20, "V": 21, "W": 22, "X": 23, "Y": 24, "Z": 25
  }
end
cin_odds() click to toggle source
# File lib/itax_code/utils.rb, line 28
def cin_odds
  {
    "0": 1,  "1": 0,  "2": 5,  "3": 7,  "4": 9,  "5": 13,
    "6": 15, "7": 17, "8": 19, "9": 21, "A": 1,  "B": 0,
    "C": 5,  "D": 7,  "E": 9,  "F": 13, "G": 15, "H": 17,
    "I": 19, "J": 21, "K": 2,  "L": 4,  "M": 18, "N": 20,
    "O": 11, "P": 3,  "Q": 6,  "R": 8,  "S": 12, "T": 14,
    "U": 16, "V": 10, "W": 22, "X": 25, "Y": 24, "Z": 23
  }
end
cin_remainders() click to toggle source
# File lib/itax_code/utils.rb, line 50
def cin_remainders
  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
end
consonants() click to toggle source
# File lib/itax_code/utils.rb, line 20
def consonants
  %w[b c d f g h j k l m n p q r s t v w x y z]
end
countries() click to toggle source
# File lib/itax_code/utils.rb, line 106
def countries
  @countries ||= JSON.parse(
    File.read("#{__dir__}/data/countries.json")
  )
end
encode_cin(code) click to toggle source
# File lib/itax_code/utils.rb, line 89
def encode_cin(code)
  tot = 0

  code.chars.each_with_index do |char, index|
    tot += cin_odds[char.to_sym]  if (index + 1).odd?
    tot += cin_evens[char.to_sym] if (index + 1).even?
  end

  cin_remainders[tot % 26]
end
extract_consonants(str) click to toggle source
# File lib/itax_code/utils.rb, line 81
def extract_consonants(str)
  str.select { |c| consonants.include? c }.join
end
extract_vowels(str) click to toggle source
# File lib/itax_code/utils.rb, line 85
def extract_vowels(str)
  str.select { |c| vowels.include? c }.join
end
months() click to toggle source
# File lib/itax_code/utils.rb, line 16
def months
  %w[A B C D E H L M P R S T]
end
municipalities() click to toggle source
# File lib/itax_code/utils.rb, line 100
def municipalities
  @municipalities ||= JSON.parse(
    File.read("#{__dir__}/data/municipalities.json")
  )
end
omocodia() click to toggle source
# File lib/itax_code/utils.rb, line 54
def omocodia
  {
    "0": "L", "1": "M", "2": "N", "3": "P", "4": "Q",
    "5": "R", "6": "S", "7": "T", "8": "U", "9": "V"
  }
end
omocodia_decode(val) click to toggle source
# File lib/itax_code/utils.rb, line 77
def omocodia_decode(val)
  val.tr omocodia_letters, omocodia_digits
end
omocodia_digits() click to toggle source
# File lib/itax_code/utils.rb, line 61
def omocodia_digits
  omocodia.keys.join
end
omocodia_encode(val) click to toggle source
# File lib/itax_code/utils.rb, line 73
def omocodia_encode(val)
  val.tr omocodia_digits, omocodia_letters
end
omocodia_letters() click to toggle source
# File lib/itax_code/utils.rb, line 65
def omocodia_letters
  omocodia.values.join
end
omocodia_subs_indexes() click to toggle source
# File lib/itax_code/utils.rb, line 69
def omocodia_subs_indexes
  [6, 7, 9, 10, 12, 13, 14]
end
regex() click to toggle source
# File lib/itax_code/utils.rb, line 3
def regex
  /^([A-Z]{3})([A-Z]{3})
    (([A-Z\d]{2})([ABCDEHLMPRST]{1})([A-Z\d]{2}))
    ([A-Z]{1}[A-Z\d]{3})
    ([A-Z]{1})$/x
end
slugged(str, separator = "-") click to toggle source
# File lib/itax_code/utils.rb, line 10
def slugged(str, separator = "-")
  str.gsub!(/\s*@\s*/, " at ")
  str.gsub!(/\s*&\s*/, " and ")
  str.parameterize(separator: separator)
end
vowels() click to toggle source
# File lib/itax_code/utils.rb, line 24
def vowels
  %w[a e i o u]
end