Sha256: 05d712e171efbe275be0bd2c6777a0a0d8a30bdfec9b44e1f8052ce34465ea4d

Contents?: true

Size: 291 Bytes

Versions: 15

Compression:

Stored size: 291 Bytes

Contents

class PhoneNumber < String
  def initialize(value)
    super(value.to_s)
  end

  def valid?
    has_ten_digits?  
  end
  
  def has_ten_digits?
    self =~ /\d{9}/
  end

  def inspect
    self.to_s
  end
  
  def to_s
    "(#{self[0..2]}) #{self[3..5]}-#{self[6..9]}" if valid?
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
valuable-0.9.14 examples/phone_number.rb
valuable-0.9.13 examples/phone_number.rb
valuable-0.9.12 examples/phone_number.rb
valuable-0.9.11 examples/phone_number.rb
valuable-0.9.10 examples/phone_number.rb
valuable-0.9.9 examples/phone_number.rb
valuable-0.9.8 examples/phone_number.rb
valuable-0.9.7 examples/phone_number.rb
valuable-0.9.6 examples/phone_number.rb
valuable-0.9.5 examples/phone_number.rb
valuable-0.9.4 examples/phone_number.rb
valuable-0.9.3 examples/phone_number.rb
valuable-0.9.2 examples/phone_number.rb
valuable-0.9.1 examples/phone_number.rb
valuable-0.9.0 examples/phone_number.rb