Class: StringChinese
- Inherits:
-
String
- Object
- String
- StringChinese
- Defined in:
- lib/a-b-chi.rb
Instance Method Summary collapse
-
#initialize ⇒ StringChinese
constructor
A new instance of StringChinese.
- #to_ruby_markup ⇒ Object
- #to_ruby_unmarked ⇒ Object
Constructor Details
#initialize ⇒ StringChinese
Returns a new instance of StringChinese.
38 39 40 41 42 43 44 |
# File 'lib/a-b-chi.rb', line 38 def initialize spec = Gem::Specification.find_by_name("a-b-chi") gem_root = spec.gem_dir @gem_lib = gem_root + "/lib" @characters = File.read("#{@gem_lib}/characters.txt").split("\n") @bpmf = File.read("#{@gem_lib}/bopomofo.txt").split("\n") end |
Instance Method Details
#to_ruby_markup ⇒ Object
52 53 54 55 56 |
# File 'lib/a-b-chi.rb', line 52 def to_ruby_markup markup = '<p style="writing-mode: tb-rl"><ruby>' (0..(self.size-1)).each { |i| markup << "<rb>#{self[i]}</rb><rp>(</rp><rt>#{@bpmf[@characters.index(self[i])]}</rt><rp>)</rp>"} markup << '</p></ruby>' end |
#to_ruby_unmarked ⇒ Object
46 47 48 49 50 |
# File 'lib/a-b-chi.rb', line 46 def to_ruby_unmarked unmarked = '' (0..(self.size-1)).each { |i| unmarked << "#{self[i]}(#{@bpmf[@characters.index(self[i])]})"} return unmarked end |