-
Notifications
You must be signed in to change notification settings - Fork 159
/
credit_card.rb
45 lines (37 loc) · 1.28 KB
/
credit_card.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require_relative './luhn_validator.rb'
require 'json'
class CreditCard
# TODO: mixin the LuhnValidator using an 'include' statement
# instance variables with automatic getter/setter methods
attr_accessor :number, :expiration_date, :owner, :credit_network
def initialize(number, expiration_date, owner, credit_network)
# TODO: initialize the instance variables listed above
end
# returns json string
def to_json
{
# TODO: setup the hash with all instance vairables to serialize into json
}.to_json
end
# returns all card information as single string
def to_s
to_json
end
# return a new CreditCard object given a serialized (JSON) representation
def self.from_s(card_s)
# TODO: deserializing a CreditCard object
end
# return a hash of the serialized credit card object
def hash
# TODO: implement this method
# - Produce a hash (using default hash method) of the credit card's
# serialized contents.
# - Credit cards with identical information should produce the same hash
end
# return a cryptographically secure hash
def hash_secure
# TODO: implement this method
# - Use sha256 to create a cryptographically secure hash.
# - Credit cards with identical information should produce the same hash
end
end