Skip to content

Commit

Permalink
added a separate Phone class to supply Phony options in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarwagya committed May 4, 2011
1 parent b79f3cf commit 610ea49
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/mongoid/conversions.rb
Expand Up @@ -13,8 +13,25 @@ def set(value)
end

def get(value)
Phony.format(value.to_s, :format => :international, :spaces => :-)
Phone.new(value)
end
end

protected

# This class is used to set different Phony options in runtime because Phony doesn't allow creating a new object
class Phone
attr_accessor :spaces, :format, :value

def initialize (value = nil, format="international", spaces = "-")
@format = format
@spaces = spaces
@value = value
end

def to_s()
Phony.format(@value.to_s, :format => @format.to_sym, :spaces => @spaces.to_sym)
end
end
end
end

0 comments on commit 610ea49

Please sign in to comment.