Skip to content

Commit

Permalink
First call is complete. Champion.
Browse files Browse the repository at this point in the history
  • Loading branch information
intinig committed Dec 11, 2013
1 parent f15f6c7 commit abd28b2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
69 changes: 65 additions & 4 deletions lib/lol/champion.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,76 @@
module Lol
class Champion


# @!attribute [r] raw
# @return [String] raw version of options Hash used to initialize Champion
attr_reader :raw

# @!attribute [r] id
# @return [Fixnum] id of Champion
attr_reader :id

# @!attribute [r] name
# @return [String] name of Champion
attr_reader :name

# @!attribute [r] active
# @return [true] if the Champion is active
# @return [false] if the Champion is disabled
attr_reader :active

# @!attribute [r] attack_rank
# @return [Fixnum] attack rank of Champion
attr_reader :attack_rank

# @!attribute [r] defense_rank
# @return [Fixnum] defense rank of Champion
attr_reader :defense_rank

# @!attribute [r] magic_rank
# @return [Fixnum] magic rank of Champion
attr_reader :magic_rank

# @!attribute [r] difficulty_rank
# @return [Fixnum] difficulty rank of Champion
attr_reader :difficulty_rank

# @!attribute [r] bot_enabled
# @return [true] if the Champion is enabled in custom bot games
# @return [false] if the Champion is disabled in custom bot games
attr_reader :bot_enabled

# @!attribute [r] free_to_play
# @return [true] if the Champion is currently free to play
# @return [false] if the Champion isn't currently free to play
attr_reader :free_to_play

# @!attribute [r] bot_mm_enabled
# @return [true] if the Champion is enabled in match made bot games
# @return [false] if the Champion is disabled in match made bot games
attr_reader :bot_mm_enabled

# @!attribute [r] ranked_play_enabled
# @return [true] if the Champion is enabled in ranked play
# @return [false] if the Champion is disabled in ranked play
attr_reader :ranked_play_enabled

# Initializes a Lol::Champion
# @param options [Hash]
# @return [Lol::Champion]
def initialize options = {}
@raw = options
end

def raw
@raw
@id = options.delete "id"
@name = options.delete "name"
@active = options.delete "active"
@attack_rank = options.delete "attackRank"
@defense_rank = options.delete "defenseRank"
@magic_rank = options.delete "magicRank"
@difficulty_rank = options.delete "difficultyRank"
@bot_enabled = options.delete "botEnabled"
@free_to_play = options.delete "freeToPlay"
@bot_mm_enabled = options.delete "botMmEnabled"
@ranked_play_enabled = options.delete "rankedPlayEnabled"
end
end
end
19 changes: 19 additions & 0 deletions spec/lol/champion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,23 @@
expect { Champion.new({ :foo => :bar }) }.not_to raise_error
end
end

describe "#raw" do
it "is readonly" do
expect { Champion.new.raw = "bar" }.to raise_error(NoMethodError)
end
end

[:id, :name, :active, :attack_rank, :defense_rank, :magic_rank, :difficulty_rank, :bot_enabled,
:free_to_play, :bot_mm_enabled, :ranked_play_enabled].each do |attr|
describe "##{attr}" do
it "accepts it as constructor" do
expect_init_attribute(Champion, attr)
end

it "is readonly" do
expect_read_only_attribute(Champion, attr)
end
end
end
end
17 changes: 17 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
c.configure_rspec_metadata!
end

def underscore s
s.to_s.scan(/[A-Z][a-z]*/).join("_").downcase
end

def camelize s
s[0] + s.to_s.split("_").each {|s| s.capitalize! }.join("")[1..-1]
end

def load_fixture subject, version, method
JSON.parse(File.read(__dir__ + "/fixtures/#{version}/#{method}-#{subject}.json"))
end

def expect_init_attribute subject, attribute
puts camelize(attribute)
expect(subject.new(camelize(attribute) => "foo").send(attribute)).to eq("foo")
end

def expect_read_only_attribute subject, attribute
expect { subject.new.send("#{attribute}=".to_sym, "bar") }.to raise_error(NoMethodError)
end

0 comments on commit abd28b2

Please sign in to comment.