Class: ItaxCode::Omocode

Inherits:
Object
  • Object
show all
Defined in:
lib/itax_code/omocode.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tax_code, utils = Utils) ⇒ Omocode

Creates a new instance for a given tax_code.

Parameters:

  • tax_code (String)
  • utils (Utils) (defaults to: Utils)


11
12
13
14
# File 'lib/itax_code/omocode.rb', line 11

def initialize(tax_code, utils = Utils)
  @tax_code = tax_code
  @utils    = utils
end

Instance Attribute Details

#tax_codeObject (readonly)

Returns the value of attribute tax_code.



5
6
7
# File 'lib/itax_code/omocode.rb', line 5

def tax_code
  @tax_code
end

#utilsObject (readonly)

Returns the value of attribute utils.



5
6
7
# File 'lib/itax_code/omocode.rb', line 5

def utils
  @utils
end

Instance Method Details

#omocodesArray

Computes the omocodes from a given tax_code by first identifying the original tax_code and then appending all the omocodes.

Returns:

  • (Array)


20
21
22
23
24
# File 'lib/itax_code/omocode.rb', line 20

def omocodes
  [original_omocode] + utils.omocodia_indexes_combos.map do |combo|
    omocode(original_omocode, combo, ->(char) { utils.omocodia_encode(char) })
  end
end

#original_omocodeString

The original omocode is the one that have all the omocody indexes decoded as number, and from which any of its omocodes are generated.

Returns:

  • (String)


30
31
32
33
34
# File 'lib/itax_code/omocode.rb', line 30

def original_omocode
  @original_omocode ||= omocode(
    tax_code, utils.omocodia_indexes, ->(char) { utils.omocodia_decode(char) }
  )
end