OSDN Git Service

左ペインの表示を実装
[praisedb/praisedb.git] / app / models / song.rb
index 54db88f..34118e1 100644 (file)
@@ -34,8 +34,12 @@ class Song < ActiveRecord::Base
     strip_ruby_base(words)
   end
 
+  def kanji
+    strip_ruby_text(words)
+  end
+
   def ruby
-    markup_html_ruby_tag(words)
+    markup_html_ruby_tag(ERB::Util.h words)
   end
 
   # 慈(いつく)しみ
@@ -45,7 +49,8 @@ class Song < ActiveRecord::Base
       to_s.
       gsub(RUBY_KANJI_HIRA)  { ruby_tag_template($1, $2) }.
       gsub(RUBY_ENGLISH_KANA){ ruby_tag_template($1, $2) }.
-      gsub(RUBY_KANA_HIRA)   { ruby_tag_template($1, $2) }
+      gsub(RUBY_KANA_HIRA)   { ruby_tag_template($1, $2) }.
+      yourself
   end
 
   def ruby_tag_template(base, text)
@@ -53,6 +58,16 @@ class Song < ActiveRecord::Base
   end
 
   def strip_ruby_base(str)
-    str.gsub(RUBY_KANJI_HIRA){ $2 }.gsub(RUBY_ENGLISH_KANA){ $2 }.gsub(RUBY_KANA_HIRA){ $2 }
+    str.gsub(RUBY_KANJI_HIRA){ $2 }.
+      gsub(RUBY_ENGLISH_KANA){ $2 }.
+      gsub(RUBY_KANA_HIRA){ $2 }.
+      yourself
+  end
+
+  def strip_ruby_text(str)
+    str.gsub(RUBY_KANJI_HIRA){ $1 }.
+      gsub(RUBY_ENGLISH_KANA){ $1 }.
+      gsub(RUBY_KANA_HIRA){ $1 }.
+      yourself
   end
 end