Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compute omocodes from the original one #22

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/itax_code/omocode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(tax_code, utils = Utils.new)
# @return [Array]
def omocodes
[original_omocode] + utils.omocodia_indexes_combos.map do |combo|
omocode(combo, ->(char) { utils.omocodia_encode(char) })
omocode(original_omocode, combo, ->(char) { utils.omocodia_encode(char) })
end
end

Expand All @@ -28,13 +28,15 @@ def omocodes
#
# @return [String]
def original_omocode
omocode(utils.omocodia_indexes, ->(char) { utils.omocodia_decode(char) })
@original_omocode ||= omocode(
tax_code, utils.omocodia_indexes, ->(char) { utils.omocodia_decode(char) }
)
end

private

def omocode(indexes, translation)
chars = tax_code[0..14].chars
def omocode(code, indexes, translation)
chars = code[0..14].chars

indexes.each do |index|
chars[index] = translation.call(chars[index])
Expand Down