Class: YoudaoFanyi::Translator
- Inherits:
-
Object
- Object
- YoudaoFanyi::Translator
- Defined in:
- lib/youdao_fanyi/translator.rb
Instance Attribute Summary collapse
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*options) ⇒ Translator
constructor
A new instance of Translator.
Constructor Details
#initialize(*options) ⇒ Translator
Returns a new instance of Translator.
7 8 9 |
# File 'lib/youdao_fanyi/translator.rb', line 7 def initialize(*) ..each {|k,v| instance_variable_set :"@#{k.to_s}", v} end |
Instance Attribute Details
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
5 6 7 |
# File 'lib/youdao_fanyi/translator.rb', line 5 def queries @queries end |
Class Method Details
.t(*words) ⇒ Object
25 26 27 |
# File 'lib/youdao_fanyi/translator.rb', line 25 def self.t(*words) translate(*words) {|connector| connector.translation} end |
.translate(*words, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/youdao_fanyi/translator.rb', line 11 def self.translate(*words, &block) = words. not_translate = .delete(:not_translate) || false words = format_words(words) if not_translate self.new(:queries => words) else words.map do |word| connector = YoudaoFanyi::Connector.new.request(word) block ? (yield connector) : connector end end end |