1 class Speech < Peta::Element
3 belongs_to :speech_balloon
4 belongs_to :speech_balloon_template
5 belongs_to :writing_format
7 validates :speech_balloon_id, :numericality => {:allow_blank => true}
8 validates :speech_balloon_template_id, :presence => true, :numericality => true, :existence => {:both => false}
9 validates :speech_balloon_template_module_name, :presence => true, :length => {:maximum => 50}
10 validates :writing_format_id, :presence => true, :numericality => true, :existence => {:both => false}
11 validates :writing_format_module_name, :presence => true, :length => {:maximum => 50}
12 validates :font_size, :presence => true, :numericality => {:only_integer => false}
13 validates :text_align, :presence => true, :numericality => true, :inclusion => { :in => 0..3 }
14 validates :fore_color, :presence => true, :numericality => {:greater_than_or_equal_to => 0, :less_than => 0x1000000}
15 validates :x, :presence => true, :numericality => true
16 validates :y, :presence => true, :numericality => true
17 validates :width, :presence => true, :numericality => true, :natural_number => true
18 validates :height, :presence => true, :numericality => true, :natural_number => true
19 validates :quotes, :length => {:maximum => 15}, :quotes_even => true
20 validates :speech_balloon_template_settings, :boost => {:boost_name => :speech_balloon_template}
21 #validates :writing_format_settings
23 scope :with_panel, -> do
24 includes(speech_balloon: :panel)
27 scope :with_speech_balloon_template, -> do
28 includes(:speech_balloon_template)
31 scope :find_index, -> do
32 with_panel.where(Panel.arel_table[:publish].gt 0).references(:panel)
35 scope :find_private, -> (operators) do
36 with_panel.where(Panel.arel_table[:author_id].eq operators.author.id).references(:panel)
39 scope :find_by_panel, -> (panel_id) do
40 find_index.where(panel_id: panel_id).references(:panel)
43 scope :find_by_speech_balloon, -> (speech_balloon_id) do
44 find_index.where(speech_balloon_id: speech_balloon_id).references(:panel)
47 scope :find_by_speech_balloon_template, -> (speech_balloon_template_id) do
48 find_index.where(speech_balloon_template_id: speech_balloon_template_id).references(:panel)
51 scope :find_by_writing_format, -> (writing_format_id) do
52 find_index.where(writing_format_id: writing_format_id).references(:panel)
55 scope :find_by_author, -> (author_id) do
56 find_index.where(Panel.arel_table[:author_id].eq author_id).references(:panel)
59 @@text_align_texts = ['left', 'left', 'right', 'center']
74 self.speech_balloon.speech_balloon_template.symbol_option
79 'top' => self.y.to_s + '%', 'left' => self.x.to_s + '%',
80 'width' => self.width.to_s + '%', 'height' => self.height.to_s + '%'
86 'font-size' => self.font_size.to_s + 'em',
87 'text-align' => self.text_align_text,
88 'color' => '#' + format("%06x", self.fore_color)
93 @@text_align_texts[self.text_align]
96 def self.public_list_where list
100 def self.by_author_list_includes
111 {:include => {:speech_balloon => {:panel => {:author => {}}, :balloon => {}, :speech_balloon_template => {} }}}
120 self.content.to_s + "\n"
124 ERB::Util.html_escape(self.content)