mtg 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,17 +7,23 @@ module MTG
7
7
  NAMES = %w(common uncommon rare mythic\ rare)
8
8
 
9
9
  def initialize(name)
10
+ name = name.to_s.strip.downcase
10
11
  unless NAMES.include?(name)
11
- raise ArgumentError, "#{name.inspect} is not one of: #{NAMES.inspect}"
12
+ raise ArgumentError, "name is not one of: #{NAMES.inspect}"
12
13
  end
13
- @name = name.to_s
14
+ @name = name
14
15
  end
15
16
 
16
- attr_reader :name
17
- alias_method :to_s, :name
17
+ def to_s(format = nil)
18
+ if format.try(:short)
19
+ {'common' => 'C', 'uncommon' => 'U', 'rare' => 'R', 'mythic rare' => 'MR'}[@name]
20
+ else
21
+ @name
22
+ end
23
+ end
18
24
 
19
25
  def <=>(rarity)
20
- NAMES.index(name) <=> NAMES.index(rarity.name)
26
+ NAMES.index(to_s) <=> NAMES.index(rarity.to_s)
21
27
  end
22
28
 
23
29
  def eql?(rarity)
@@ -25,12 +31,12 @@ module MTG
25
31
  end
26
32
 
27
33
  def hash
28
- name.hash
34
+ @name.hash
29
35
  end
30
36
 
31
37
  NAMES.each do |name|
32
38
  define_method(name.gsub(/\s/, '_') + '?') do
33
- self.name == name
39
+ @name == name
34
40
  end
35
41
  end
36
42
 
data/mtg-0.0.1.gem ADDED
Binary file
data/mtg.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mtg'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.authors = ['Austin Schneider']
5
5
  s.email = "soccer022483@gmail.com"
6
6
  s.description = 'Objects such as cards, colors, mana costs, etc relating to the Magic, The Gathering trading card game.'
7
- # s.homepage = ""
7
+ s.homepage = "http://github.com/soccer022483/mtg"
8
8
  s.summary = 'An MTG gem'
9
9
  # s.post_install_message "Thanks for installing!"
10
10
  s.files = Dir[
@@ -103,4 +103,31 @@ describe MTG::Card::Rarity do
103
103
  end
104
104
  end
105
105
 
106
+ describe "#to_s" do
107
+ MTG::Card::Rarity::NAMES.each do |name|
108
+ context "when the rarity is #{name.inspect}" do
109
+ context "when the format is ':short'" do
110
+ before do
111
+ @short_name = case name
112
+ when 'common' then 'C'
113
+ when 'uncommon' then 'U'
114
+ when 'rare' then 'R'
115
+ when 'mythic rare' then 'MR'
116
+ end
117
+ end
118
+
119
+ it "returns #{@short_name.inspect}" do
120
+ MTG::Card::Rarity.new(name).to_s(:short).should == @short_name
121
+ end
122
+ end
123
+
124
+ context "when the format is not ':short'" do
125
+ it "returns #{name.inspect}" do
126
+ MTG::Card::Rarity.new(name).to_s.should == name
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+
106
133
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Austin Schneider
@@ -44,6 +44,7 @@ files:
44
44
  - README
45
45
  - mtg.gemspec
46
46
  - LICENSE
47
+ - mtg-0.0.1.gem
47
48
  - example.rb
48
49
  - lib/mtg/card/rarity.rb
49
50
  - lib/mtg/card/base.rb
@@ -60,7 +61,7 @@ files:
60
61
  - spec/mtg/set_spec.rb
61
62
  - spec/mtg/nameable_spec.rb
62
63
  has_rdoc: true
63
- homepage:
64
+ homepage: http://github.com/soccer022483/mtg
64
65
  licenses: []
65
66
 
66
67
  post_install_message: