From 1ecba46a8cb0db962908f47ab4e054ee04804a4a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 24 Sep 2017 11:33:55 -0400 Subject: Added OT gender field --- app/jobs/pokeviewer/extract_save_data_job.rb | 1 + app/models/pokeviewer/pokemon.rb | 3 +++ app/views/pokeviewer/pokemon/show.html.haml | 2 +- db/migrate/20170924152817_add_ot_gender_to_pokemon.rb | 5 +++++ test/dummy/db/schema.rb | 3 ++- 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170924152817_add_ot_gender_to_pokemon.rb diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb index e4f3ae2..0a9b790 100644 --- a/app/jobs/pokeviewer/extract_save_data_job.rb +++ b/app/jobs/pokeviewer/extract_save_data_job.rb @@ -27,6 +27,7 @@ module Pokeviewer r.species_id = param["species"] r.ot_name = param["otName"] r.ot_number = param["otId"] + r.ot_gender = param["otGender"] if param["metLevel"] == 0 r.met_type = :hatched diff --git a/app/models/pokeviewer/pokemon.rb b/app/models/pokeviewer/pokemon.rb index 1410d37..1e3bfc8 100644 --- a/app/models/pokeviewer/pokemon.rb +++ b/app/models/pokeviewer/pokemon.rb @@ -14,6 +14,9 @@ module Pokeviewer validates :ot_number, presence: true, numericality: { greater_than_or_equal_to: 0, only_integer: true } + validates :ot_gender, presence: true + enumerize :ot_gender, in: [:female, :male] + validates :met_level, presence: true, numericality: { greater_than_or_equal_to: 1, only_integer: true }, if: Proc.new { |a| a.met_type == :normal } diff --git a/app/views/pokeviewer/pokemon/show.html.haml b/app/views/pokeviewer/pokemon/show.html.haml index b61917c..a38d641 100644 --- a/app/views/pokeviewer/pokemon/show.html.haml +++ b/app/views/pokeviewer/pokemon/show.html.haml @@ -6,7 +6,7 @@ .pokemon-name= @pokemon.revisions.last.nickname .pokemon-ot OT/ - %span{ class: @pokemon.gender }>= @pokemon.ot_name + %span{ class: @pokemon.ot_gender }>= @pokemon.ot_name .pokemon-id= "ID/#{@pokemon.ot_number}" .pokemon-level= "Lv. #{@pokemon.revisions.last.level}" %table.pokemon-ivs diff --git a/db/migrate/20170924152817_add_ot_gender_to_pokemon.rb b/db/migrate/20170924152817_add_ot_gender_to_pokemon.rb new file mode 100644 index 0000000..b5f715c --- /dev/null +++ b/db/migrate/20170924152817_add_ot_gender_to_pokemon.rb @@ -0,0 +1,5 @@ +class AddOtGenderToPokemon < ActiveRecord::Migration[5.1] + def change + add_column :pokeviewer_pokemon, :ot_gender, :string, null: false, default: "" + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 1ce4679..9d6d773 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170924035127) do +ActiveRecord::Schema.define(version: 20170924152817) do create_table "pokeviewer_moves", force: :cascade do |t| t.string "name", limit: 191, null: false @@ -37,6 +37,7 @@ ActiveRecord::Schema.define(version: 20170924035127) do t.string "unown_letter", limit: 1 t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "ot_gender", default: "", null: false t.index ["key"], name: "index_pokeviewer_pokemon_on_key", unique: true t.index ["species_id"], name: "index_pokeviewer_pokemon_on_species_id" t.index ["trainer_id"], name: "index_pokeviewer_pokemon_on_trainer_id" -- cgit 1.4.1