Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First round of skills stuff

  • Loading branch information...
commit ccfeeb45c7d295fcc5dc909235a6d6601e7e34be 1 parent e5d9047
Mitchell Lane authored
View
0  app/assets/images/skills/Ahri_Charm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  app/assets/images/skills/Ahri_Essence_Theft.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  app/assets/images/skills/Ahri_Fox_Fire.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  app/assets/images/skills/Ahri_Orb_Of Deception.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
0  app/assets/images/skills/Ahri_Spirit_Rush.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
34 app/models/champion.rb
@@ -1,5 +1,5 @@
class Champion < ActiveRecord::Base
-
+ has_many :skills
has_many :votes
has_many :counterpicks, :through => :votes, :source => :counterpick
# ^^^ this relationship means you can do Champion.find(1).counterpicks and it will return all champs voted as counterpicks.
@@ -28,6 +28,38 @@ def updateChampData
self.health_regen_per_level = url.search(".view_content_frame .stats_table tr:nth-child(7) .ability_per_level_stat").inner_html.gsub(" / per level", "").gsub("+", "")
self.resource_regen = url.search(".view_content_frame .stats_table tr:nth-child(8) .stats_value").inner_html
self.resource_regen_per_level = url.search(".view_content_frame .stats_table tr:nth-child(8) .ability_per_level_stat").inner_html.gsub(" / per level", "").gsub("+", "")
+
+
+ self.skills.delete_all
+ url.search(".abilities_table tr").each do |tr|
+ td = tr.search(".ability_detail")
+ dd = td.search(".ability_stats dd")
+ s = Skill.create({
+ :name => td.search(".ability_name").inner_html,
+ :description => td.search(".ability_description").inner_html,
+ :effect => td.search(".ability_effect").inner_html,
+ :cost => (dd.any? ? dd[0].inner_html : nil),
+ :range => (dd.any? ? dd[1].inner_html.to_i : nil),
+ })
+
+ Rails.logger.debug tr.search(".ability_icon")[0].attributes["src"]
+ puts tr.search(".ability_icon")[0].attributes["src"]
+ iconURL = "http://na.leagueoflegends.com" + tr.search(".ability_icon")[0].attributes["src"]
+
+ if FileTest.exists?("app/assets/images/skills/" + self.name + "_" + s.name.titleize.sub(" ", "_") + ".png") == false
+ open("app/assets/images/skills/" + self.name + "_" + s.name.titleize.sub(" ", "_") + ".png", 'wb') do |file|
+ file << open( iconURL ).read
+ end
+ s.url = "/assets/skills/" + self.name + "_" + s.name.titleize.sub(" ", "_") + ".png"
+ s.save
+ sleep 1
+ end
+
+ self.skills << s
+
+ end
+
+
end
end
View
3  app/models/skill.rb
@@ -0,0 +1,3 @@
+class Skill < ActiveRecord::Base
+ belongs_to :champion
+end
View
15 db/migrate/20120126021741_create_skills.rb
@@ -0,0 +1,15 @@
+class CreateSkills < ActiveRecord::Migration
+ def change
+ create_table :skills do |t|
+ t.integer :champion_id
+ t.string :image_url
+ t.string :name
+ t.text :description
+ t.text :effect
+ t.string :cost
+ t.integer :range
+
+ t.timestamps
+ end
+ end
+end
View
15 db/schema.rb
@@ -11,7 +11,8 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120126035908) do
+ActiveRecord::Schema.define(:version => 20120126021741) do
+
create_table "champions", :force => true do |t|
t.string "name"
@@ -57,6 +58,18 @@
t.datetime "updated_at"
end
+ create_table "skills", :force => true do |t|
+ t.integer "champion_id"
+ t.string "image_url"
+ t.string "name"
+ t.text "description"
+ t.text "effect"
+ t.string "cost"
+ t.integer "range"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
t.string "encrypted_password", :limit => 128, :default => "", :null => false
View
17 test/fixtures/skills.yml
@@ -0,0 +1,17 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
+
+one:
+ champion_id: 1
+ image_url: MyString
+ name: MyString
+ description: MyText
+ cost: MyString
+ range: 1
+
+two:
+ champion_id: 1
+ image_url: MyString
+ name: MyString
+ description: MyText
+ cost: MyString
+ range: 1
View
7 test/unit/skill_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SkillTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.