Class: Costume

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/costume.rb

Constant Summary collapse

PRESET_COSTUME_SETTINGS =
{ name: "car1", tag_list: %w(Preset Car) },
{ name: "car2", tag_list: %w(Preset Car) },
{ name: "car3", tag_list: %w(Preset Car) },
{ name: "car4", tag_list: %w(Preset Car) },
{ name: "cat1", tag_list: %w(Preset Animal Cat) },
{ name: "cat2", tag_list: %w(Preset Animal Cat) },
{ name: "cat3", tag_list: %w(Preset Animal Cat) },
{ name: "frog1", tag_list: %w(Preset Aminal Frog) },
{ name: "ball1", tag_list: %w(Preset Ball) },
{ name: "ball2", tag_list: %w(Preset Ball) },
{ name: "ball3", tag_list: %w(Preset Ball) },
{ name: "ball4", tag_list: %w(Preset Ball) },
{ name: "ball5", tag_list: %w(Preset Ball) },
{ name: "ball6", tag_list: %w(Preset Ball) },
{ name: "ryu1", tag_list: %w(Preset Human Ninja) },
{ name: "ryu2", tag_list: %w(Preset Human Ninja) },
{ name: "taichi1", tag_list: %w(Preset Animal Ninja) },
{ name: "taichi2", tag_list: %w(Preset Animal Ninja) }

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_presetsObject



31
32
33
34
35
36
37
38
39
# File 'app/models/costume.rb', line 31

def create_presets
  PRESET_COSTUME_SETTINGS.each.with_index do |setting, index|
    costume = Costume.find_or_create_by(name: setting[:name],
                                        position: index,
                                        preset: true)
    costume.tag_list = setting[:tag_list]
    costume.save!
  end
end

.destroy_presetsObject



41
42
43
44
# File 'app/models/costume.rb', line 41

def destroy_presets
  names = PRESET_COSTUME_SETTINGS.map { |s| s[:name] }
  where(name: names, preset: true).destroy_all
end

Instance Method Details

#basenameObject



64
65
66
# File 'app/models/costume.rb', line 64

def basename
  "#{name}.png"
end

#basename=(val) ⇒ Object



60
61
62
# File 'app/models/costume.rb', line 60

def basename=(val)
  self.name = val.sub(/\.png$/, "")
end

#pathObject



51
52
53
54
55
56
57
58
# File 'app/models/costume.rb', line 51

def path
  if preset?
    Rails.root.join("public/smalruby/assets/#{basename}")
  else
    s = "~/#{user.name}/__assets__/#{basename}"
    Pathname(s).expand_path
  end
end

#urlObject



47
48
49
# File 'app/models/costume.rb', line 47

def url
  "/smalruby/assets/#{basename}"
end