Sha256: 5d0677b6c721364d66bcb0b55ed6876963ffa3a48683391728af20a1a4980fa4
Contents?: true
Size: 776 Bytes
Versions: 11
Compression:
Stored size: 776 Bytes
Contents
#encoding: UTF-8 module Termit class UrlConstructor Host = "https://www.bing.com" def initialize options @options = options end def url @options[:talk] ? construct_sound_url : construct_text_url end private def construct_text_url "#{Host}/translator/api/Translate/TranslateArray?from=#{@options.fetch(:source_lang)}&to=#{@options.fetch(:target_lang)}" end def construct_sound_url "#{Host}/translator/api/language/Speak?locale=#{transform_country_code(@options.fetch(:target_lang))}&gender=male&media=audio/mp3&text=#{URI.encode(@options.fetch(:text))}" end def transform_country_code(code) if code == :en 'en-US' else "#{code}-#{code.upcase}" end end end end
Version data entries
11 entries across 11 versions & 1 rubygems