Class: Phoney::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/phoney/rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options={})
  @max_digits = options[:max_digits]
  
  @min_value = options[:min_value]
  @max_value = options[:max_value]
  
  @areacode_length = options[:areacode_length]
  @areacode_offset = options[:areacode_offset]
  
  @pattern = options[:pattern]
  @flags   = options[:flags]
end

Instance Attribute Details

#areacode_lengthObject (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_offsetObject (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_digitsObject (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_valueObject (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_valueObject (readonly)

Returns the value of attribute min_value.



28
29
30
# File 'lib/phoney/rules.rb', line 28

def min_value
  @min_value
end

#patternObject (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

#flagsObject



52
53
54
# File 'lib/phoney/rules.rb', line 52

def flags
  @flags || []
end

#matches?(number) ⇒ Boolean

Returns:

  • (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