now generates html!
This commit is contained in:
1 parent
33da302968
commit
701d78a818
59 files changed
+355
-238
No files matched your search
@@ -1,65 +1,71 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
class Card
|
||||
|
||||
attr_reader :rank, :suit
|
||||
|
||||
def initialize(str)
|
||||
r = str[0,1].downcase
|
||||
s = str[1,1].downcase
|
||||
@suit = case s
|
||||
when 's' then :spades
|
||||
when 'h' then :hearts
|
||||
when 'd' then :diamonds
|
||||
when 'c' then :clubs
|
||||
end
|
||||
@rank = case r
|
||||
when '2'..'9' then r.to_i
|
||||
when 't' then 10
|
||||
when 'j' then 11
|
||||
when 'q' then 12
|
||||
when 'k' then 13
|
||||
when 'a' then 14
|
||||
end
|
||||
end
|
||||
|
||||
def rank_s
|
||||
case @rank
|
||||
when 2..10 then @rank.to_s
|
||||
when 11 then "Jack"
|
||||
when 12 then "Queen"
|
||||
when 13 then "King"
|
||||
when 14 then "Ace"
|
||||
end
|
||||
end
|
||||
|
||||
def suit_s
|
||||
@suit.to_s.capitalize
|
||||
end
|
||||
|
||||
def to_s
|
||||
rank_s + "-" + suit_s
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@rank == other.rank && @suit == other.suit
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
if @rank != other.rank
|
||||
@rank <=> other.rank
|
||||
else
|
||||
# order is Spades, Hearts, Diamonds, Clubs (conveniently reverse alphabetical)
|
||||
other.suit_s <=> suit_s
|
||||
end
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
self == other
|
||||
end
|
||||
|
||||
def hash
|
||||
to_s.hash
|
||||
end
|
||||
end
|
||||
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
class Card
|
||||
|
||||
attr_reader :rank, :suit
|
||||
|
||||
def initialize(str)
|
||||
r = str[0,1].downcase
|
||||
s = str[1,1].downcase
|
||||
@suit = case s
|
||||
when 's' then :spades
|
||||
when 'h' then :hearts
|
||||
when 'd' then :diamonds
|
||||
when 'c' then :clubs
|
||||
end
|
||||
@rank = case r
|
||||
when '2'..'9' then r.to_i
|
||||
when 't' then 10
|
||||
when 'j' then 11
|
||||
when 'q' then 12
|
||||
when 'k' then 13
|
||||
when 'a' then 14
|
||||
end
|
||||
end
|
||||
|
||||
def rank_long_s
|
||||
['2','3','4','5','6','7','8','9','10','Jack','Queen','King','Ace'][@rank-2]
|
||||
end
|
||||
|
||||
def suit_long_s
|
||||
@suit.to_s.capitalize
|
||||
end
|
||||
|
||||
def rank_s
|
||||
['2','3','4','5','6','7','8','9','t','j','q','k','a'][@rank-2]
|
||||
end
|
||||
|
||||
def suit_s
|
||||
{:spades => 's', :hearts => 'h', :diamonds => 'd', :clubs => 'c'}[@suit]
|
||||
end
|
||||
|
||||
def to_s
|
||||
rank_s + suit_s
|
||||
end
|
||||
|
||||
def to_long_s
|
||||
rank_long_s + '-' + suit_long_s
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
@rank == other.rank && @suit == other.suit
|
||||
end
|
||||
|
||||
def <=>(other)
|
||||
if @rank != other.rank
|
||||
@rank <=> other.rank
|
||||
else
|
||||
# order is Spades, Hearts, Diamonds, Clubs (conveniently reverse alphabetical)
|
||||
other.suit_s <=> suit_s
|
||||
end
|
||||
end
|
||||
|
||||
def eql?(other)
|
||||
self == other
|
||||
end
|
||||
|
||||
def hash
|
||||
to_s.hash
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user