Class: PgCreditcard
- Inherits:
-
Object
- Object
- PgCreditcard
- Defined in:
- lib/pg_creditcard.rb
Instance Method Summary collapse
- #cardexpmonth ⇒ Object
- #cardexpyear ⇒ Object
- #cardholder ⇒ Object
- #cardnumber ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(options) ⇒ PgCreditcard
constructor
A new instance of PgCreditcard.
- #type ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ PgCreditcard
Returns a new instance of PgCreditcard.
5 6 7 8 9 10 11 12 |
# File 'lib/pg_creditcard.rb', line 5 def initialize() raise ArgumentError if .nil? @name = [:name] @number = [:number] @month = [:month] @year = set_year([:year]) @cvv = [:cvv] end |
Instance Method Details
#cardexpmonth ⇒ Object
37 38 39 |
# File 'lib/pg_creditcard.rb', line 37 def cardexpmonth @month end |
#cardexpyear ⇒ Object
41 42 43 |
# File 'lib/pg_creditcard.rb', line 41 def cardexpyear @year[2..3] end |
#cardholder ⇒ Object
29 30 31 |
# File 'lib/pg_creditcard.rb', line 29 def cardholder @name end |
#cardnumber ⇒ Object
33 34 35 |
# File 'lib/pg_creditcard.rb', line 33 def cardnumber @number end |
#expired? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/pg_creditcard.rb', line 23 def expired? today = Time.now expiry = Time.new(@year, @month, days_in_a_month(@year, @month)) today > expiry end |
#type ⇒ Object
14 15 16 17 |
# File 'lib/pg_creditcard.rb', line 14 def type return nil if @number.nil? @type ||= @number.to_s.creditcard_type end |
#valid? ⇒ Boolean
19 20 21 |
# File 'lib/pg_creditcard.rb', line 19 def valid? @number.to_s.creditcard? end |