Class: Phoney::Rule
- Inherits:
-
Object
- Object
- Phoney::Rule
- Defined in:
- lib/phoney/rules.rb
Instance Attribute Summary collapse
-
#areacode_length ⇒ Object
readonly
Returns the value of attribute areacode_length.
-
#areacode_offset ⇒ Object
readonly
Returns the value of attribute areacode_offset.
-
#max_digits ⇒ Object
readonly
Returns the value of attribute max_digits.
-
#max_value ⇒ Object
readonly
Returns the value of attribute max_value.
-
#min_value ⇒ Object
readonly
Returns the value of attribute min_value.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #flags ⇒ Object
-
#initialize(options = {}) ⇒ Rule
constructor
A new instance of Rule.
- #matches?(number) ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Rule
Returns a new instance of Rule.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/phoney/rules.rb', line 30 def initialize(={}) @max_digits = [:max_digits] @min_value = [:min_value] @max_value = [:max_value] @areacode_length = [:areacode_length] @areacode_offset = [:areacode_offset] @pattern = [:pattern] @flags = [:flags] end |
Instance Attribute Details
#areacode_length ⇒ Object (readonly)
Returns the value of attribute areacode_length.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def areacode_length @areacode_length end |
#areacode_offset ⇒ Object (readonly)
Returns the value of attribute areacode_offset.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def areacode_offset @areacode_offset end |
#max_digits ⇒ Object (readonly)
Returns the value of attribute max_digits.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def max_digits @max_digits end |
#max_value ⇒ Object (readonly)
Returns the value of attribute max_value.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def max_value @max_value end |
#min_value ⇒ Object (readonly)
Returns the value of attribute min_value.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def min_value @min_value end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
28 29 30 |
# File 'lib/phoney/rules.rb', line 28 def pattern @pattern end |
Instance Method Details
#<=>(other) ⇒ Object
43 44 45 |
# File 'lib/phoney/rules.rb', line 43 def <=>(other) max_digits <=> other.max_digits end |
#flags ⇒ Object
52 53 54 |
# File 'lib/phoney/rules.rb', line 52 def flags @flags || [] end |
#matches?(number) ⇒ Boolean
47 48 49 50 |
# File 'lib/phoney/rules.rb', line 47 def matches?(number) value = number.to_s[0, max_value.to_s.length].to_i (min_value..max_value).member?(value) && number.length <= max_digits end |