Class: MtgDb::Models::Card
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- MtgDb::Models::Card
- Defined in:
- lib/mtg_db/models.rb
Instance Method Summary collapse
- #is_planeswalker? ⇒ Boolean
-
#is_transformable? ⇒ Boolean
Card.collect {|c| c if c.is_transformable?}.compact.
- #is_vanguard? ⇒ Boolean
-
#power=(new_power) ⇒ Object
When power is non-integer (e.g. *), store it in the NonIntAttribute table and use a dummy value in Card table.
-
#subtype=(new_subtype) ⇒ Object
Take care of assignment to the foreign key.
-
#supertype=(new_supertype) ⇒ Object
Take care of assignment to the foreign key.
- #toughness=(new_toughness) ⇒ Object
Instance Method Details
#is_planeswalker? ⇒ Boolean
64 65 66 |
# File 'lib/mtg_db/models.rb', line 64 def is_planeswalker? supertype.name == 'Planeswalker' end |
#is_transformable? ⇒ Boolean
Card.collect {|c| c if c.is_transformable?}.compact
69 70 71 |
# File 'lib/mtg_db/models.rb', line 69 def is_transformable? rules =~ /transform/io end |
#is_vanguard? ⇒ Boolean
60 61 62 |
# File 'lib/mtg_db/models.rb', line 60 def is_vanguard? supertype.name == 'Vanguard' end |
#power=(new_power) ⇒ Object
When power is non-integer (e.g. *), store it in the NonIntAttribute table and use a dummy value in Card table
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mtg_db/models.rb', line 32 def power=(new_power) if !new_power.nil? if !looks_like_number?(new_power) attr = NonIntAttribute.find(original_attribute: new_power) if attr.nil? card_attribute = -65_535 + NonIntAttribute.all.size attr = NonIntAttribute.find_or_create(original_attribute: new_power, card_attribute: card_attribute) end super(attr.card_attribute) else super(new_power) end else super(new_power) end end |
#subtype=(new_subtype) ⇒ Object
Take care of assignment to the foreign key
24 25 26 27 28 29 |
# File 'lib/mtg_db/models.rb', line 24 def subtype=(new_subtype) if new_subtype.is_a? String value = Subtype.find_or_create(name: new_subtype) end super(value) end |
#supertype=(new_supertype) ⇒ Object
Take care of assignment to the foreign key
16 17 18 19 20 21 |
# File 'lib/mtg_db/models.rb', line 16 def supertype=(new_supertype) if new_supertype.is_a? String value = Supertype.find_or_create(name: new_supertype) end super(value) end |
#toughness=(new_toughness) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mtg_db/models.rb', line 49 def toughness=(new_toughness) return if new_toughness.nil? if looks_like_number?(new_toughness) super(new_toughness) else attr = find_or_create_non_int_attribute(new_toughness) super(attr.card_attribute) end end |