Permalink
Browse files

First round of skills stuff

  • Loading branch information...
1 parent e5d9047 commit ccfeeb45c7d295fcc5dc909235a6d6601e7e34be Mitchell Lane committed Jan 26, 2012
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -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
@@ -0,0 +1,3 @@
+class Skill < ActiveRecord::Base
+ belongs_to :champion
+end
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class SkillTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end

0 comments on commit ccfeeb4

Please sign in to comment.