class AsianCharacter::Word
Attributes
cache[R]
Public Class Methods
new(word)
click to toggle source
# File lib/asian_character/word.rb, line 5 def initialize(word) @word = word @cache = false end
Public Instance Methods
pinyin()
click to toggle source
# File lib/asian_character/word.rb, line 10 def pinyin if @pinyin @cache= true return @pinyin end @cache = false url = 'http://chinese.biodinfo.org/'\ 'ChineseCharactorWebService.asmx/'\ 'GetWordPinyin?word=' + URI.escape(@word) + '&psd=1' res = RestClient.get(url) res.gsub!(/\s/, ' ') res=res.match(%r|<string.*>([a-z0-9]+)</string>|) @pinyin = res ? res[1].strip : nil end
sound_url()
click to toggle source
# File lib/asian_character/word.rb, line 26 def sound_url if @sound_url @cache = true return @sound_url end @cache = false url = 'http://chinese.biodinfo.org/'\ 'ChineseCharactorWebService.asmx/'\ 'GetWordPinyinSoundMP3?word=' + URI.escape(@word) + '&psd=1' res = RestClient.get(url) res.gsub!(/\s/, ' ') res=res.match(%r|<string.*>\s*(.+)\s*</string>|) @sound_url = res ? res[1].strip : nil end