Class: Israeli::PhoneResult
Overview
Result object for phone validation with type detection and formatting.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Result
#normalized, #original, #reason
Instance Method Summary collapse
-
#formatted(style: :dashed) ⇒ String?
Format the phone number.
-
#initialize(original:, normalized:, valid:, reason: nil, type: nil) ⇒ PhoneResult
constructor
A new instance of PhoneResult.
-
#landline? ⇒ Boolean
True if this is a landline phone.
-
#mobile? ⇒ Boolean
True if this is a mobile phone.
-
#voip? ⇒ Boolean
True if this is a VoIP phone.
Methods inherited from Result
#invalid?, #to_s, #valid?, #value
Constructor Details
#initialize(original:, normalized:, valid:, reason: nil, type: nil) ⇒ PhoneResult
Returns a new instance of PhoneResult.
77 78 79 80 |
# File 'lib/israeli/result.rb', line 77 def initialize(original:, normalized:, valid:, reason: nil, type: nil) super(original: original, normalized: normalized, valid: valid, reason: reason) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
74 75 76 |
# File 'lib/israeli/result.rb', line 74 def type @type end |
Instance Method Details
#formatted(style: :dashed) ⇒ String?
Format the phone number.
101 102 103 104 105 |
# File 'lib/israeli/result.rb', line 101 def formatted(style: :dashed) return nil unless valid? Validators::Phone.format(@normalized, style: style) end |
#landline? ⇒ Boolean
Returns true if this is a landline phone.
88 89 90 |
# File 'lib/israeli/result.rb', line 88 def landline? type == :landline end |
#mobile? ⇒ Boolean
Returns true if this is a mobile phone.
83 84 85 |
# File 'lib/israeli/result.rb', line 83 def mobile? type == :mobile end |
#voip? ⇒ Boolean
Returns true if this is a VoIP phone.
93 94 95 |
# File 'lib/israeli/result.rb', line 93 def voip? type == :voip end |