Class: Baseh::Profile::Prepared
- Inherits:
-
Object
- Object
- Baseh::Profile::Prepared
- Defined in:
- lib/baseh/profile.rb
Overview
Immutable, fully validated profile with pre-computed derived values.
Instance Attribute Summary collapse
-
#aliases ⇒ Object
readonly
Returns the value of attribute aliases.
-
#blocklist ⇒ Object
readonly
Returns the value of attribute blocklist.
-
#body_alphabet ⇒ Object
readonly
Returns the value of attribute body_alphabet.
-
#body_length ⇒ Object
readonly
Returns the value of attribute body_length.
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
-
#case_sensitive ⇒ Object
readonly
Returns the value of attribute case_sensitive.
-
#checksum_alphabet ⇒ Object
readonly
Returns the value of attribute checksum_alphabet.
-
#checksum_length ⇒ Object
readonly
Returns the value of attribute checksum_length.
-
#checksum_modulus ⇒ Object
readonly
Returns the value of attribute checksum_modulus.
-
#grouping ⇒ Object
readonly
Returns the value of attribute grouping.
-
#permutation ⇒ Object
readonly
Returns the value of attribute permutation.
-
#profanity_mode ⇒ Object
readonly
Returns the value of attribute profanity_mode.
-
#profile_id ⇒ Object
readonly
Returns the value of attribute profile_id.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(profile) ⇒ Prepared
constructor
A new instance of Prepared.
Constructor Details
#initialize(profile) ⇒ Prepared
Returns a new instance of Prepared.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/baseh/profile.rb', line 24 def initialize(profile) validate_type!(profile) @profile_id = validate_profile_id!(profile[:profile_id]) @case_sensitive = profile[:case_sensitive] == true @body_alphabet = validate_body_alphabet!(profile[:body_alphabet]) @body_length = validate_integer!(profile[:body_length], 1, 32, "bodyLength") @checksum_length = validate_integer!(profile[:checksum_length], 0, 8, "checksumLength") @checksum_alphabet = validate_checksum_alphabet!( profile[:checksum_alphabet], @checksum_length ) # Spec 18: validation happens before the vowel strip so malformed # alphabets are reported as such, then no-vowels strips and # re-validates the result. @profanity_mode = validate_profanity_mode!(profile[:profanity]) if @profanity_mode == "no-vowels" @body_alphabet = Profanity.strip_vowels(@body_alphabet) @checksum_alphabet = Profanity.strip_vowels(@checksum_alphabet) validate_stripped!(@body_alphabet, "body") validate_stripped!(@checksum_alphabet, "checksum") if @checksum_length.positive? @body_alphabet.freeze @checksum_alphabet.freeze end @blocklist = if @profanity_mode == "blocklist" Profanity.effective_blocklist(profile[:profanity]).freeze else [].freeze end @separator = validate_separator!( profile[:separator].to_s, @body_alphabet, @checksum_alphabet ) @aliases = validate_aliases!( profile[:aliases] || {}, @body_alphabet, @checksum_alphabet, @case_sensitive ) @grouping = validate_grouping!( profile[:grouping], @separator, @body_length, @checksum_length ) @permutation = validate_permutation!(profile[:permutation] || { enabled: false }) @capacity = @body_alphabet.length**@body_length @checksum_modulus = [@checksum_alphabet.length, 1].max**@checksum_length freeze end |
Instance Attribute Details
#aliases ⇒ Object (readonly)
Returns the value of attribute aliases.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def aliases @aliases end |
#blocklist ⇒ Object (readonly)
Returns the value of attribute blocklist.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def blocklist @blocklist end |
#body_alphabet ⇒ Object (readonly)
Returns the value of attribute body_alphabet.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def body_alphabet @body_alphabet end |
#body_length ⇒ Object (readonly)
Returns the value of attribute body_length.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def body_length @body_length end |
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def capacity @capacity end |
#case_sensitive ⇒ Object (readonly)
Returns the value of attribute case_sensitive.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def case_sensitive @case_sensitive end |
#checksum_alphabet ⇒ Object (readonly)
Returns the value of attribute checksum_alphabet.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def checksum_alphabet @checksum_alphabet end |
#checksum_length ⇒ Object (readonly)
Returns the value of attribute checksum_length.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def checksum_length @checksum_length end |
#checksum_modulus ⇒ Object (readonly)
Returns the value of attribute checksum_modulus.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def checksum_modulus @checksum_modulus end |
#grouping ⇒ Object (readonly)
Returns the value of attribute grouping.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def grouping @grouping end |
#permutation ⇒ Object (readonly)
Returns the value of attribute permutation.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def permutation @permutation end |
#profanity_mode ⇒ Object (readonly)
Returns the value of attribute profanity_mode.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def profanity_mode @profanity_mode end |
#profile_id ⇒ Object (readonly)
Returns the value of attribute profile_id.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def profile_id @profile_id end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
19 20 21 |
# File 'lib/baseh/profile.rb', line 19 def separator @separator end |
Class Method Details
.fail_profile!(reason) ⇒ Object
73 74 75 |
# File 'lib/baseh/profile.rb', line 73 def self.fail_profile!(reason) raise BasehError.new("INVALID_PROFILE", "Invalid baseH profile: #{reason}", safe_for_customer: false) end |