Class: AsianCharacter::Word
- Inherits:
-
Object
- Object
- AsianCharacter::Word
- Defined in:
- lib/asian_character/word.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
-
#initialize(word) ⇒ Word
constructor
A new instance of Word.
- #pinyin ⇒ Object
- #sound_url ⇒ Object
Constructor Details
#initialize(word) ⇒ Word
Returns a new instance of Word.
5 6 7 8 |
# File 'lib/asian_character/word.rb', line 5 def initialize(word) @word = word @cache = false end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
3 4 5 |
# File 'lib/asian_character/word.rb', line 3 def cache @cache end |
Instance Method Details
#pinyin ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/asian_character/word.rb', line 10 def 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 ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |