class Shanbay::Data
Attributes
audio[RW]
audio_address[RW]
audio_name[RW]
cn_definition[RW]
content[RW]
definition[RW]
en_definition[RW]
en_definitions[RW]
has_audio[RW]
local_us_audio[RW]
num_sense[RW]
pron[RW]
pronunciation[RW]
pronunciations[RW]
raw[RW]
sense_id[RW]
uk_audio[RW]
uk_pronunciation[RW]
us_audio[RW]
us_pronunciation[RW]
Public Class Methods
new()
click to toggle source
# File lib/shanbay/data.rb, line 84 def initialize end
Public Instance Methods
content=(word)
click to toggle source
# File lib/shanbay/data.rb, line 87 def content=(word) @content = word @local_us_audio = ::Tempfile.new([content.to_s, ".mp3"]) end
play_us_audio()
click to toggle source
# File lib/shanbay/data.rb, line 120 def play_us_audio # if local_us_audio.size > 0 # # if ENV["_system_name"] == "OSX" # if which("afplay") # fork { exec "afplay", local_us_audio.path } # elsif which("ffplay") # # fork { exec "ffplay", " -nodisp", " -autoexit ", local_us_audio.path, " >/dev/null 2>&1" } # fork { # system("ffplay -nodisp -autoexit #{local_us_audio.path} >/dev/null 2>&1 ") # } # end # end if us_audio if which("afplay") fork { exec "afplay", us_audio } elsif which("ffplay") # fork { exec "ffplay", " -nodisp", " -autoexit ", us_audio, " >/dev/null 2>&1" } fork { system("ffplay -nodisp -autoexit #{us_audio} >/dev/null 2>&1 ") } end pre_download_us_audio end end
pre_download_us_audio()
click to toggle source
# File lib/shanbay/data.rb, line 92 def pre_download_us_audio return if local_us_audio.size > 0 ::EM.run do url = us_audio http = ::EM::HttpRequest.new(url).get http.callback { local_us_audio.write(http.response) local_us_audio.rewind ::EM.stop } http.errback { ::EM.stop } end end
to_hash()
click to toggle source
# File lib/shanbay/data.rb, line 146 def to_hash @raw end
to_json()
click to toggle source
# File lib/shanbay/data.rb, line 150 def to_json @raw.to_json end
which(cmd)
click to toggle source
# File lib/shanbay/data.rb, line 109 def which(cmd) exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| exts.each { |ext| exe = File.join(path, "#{cmd}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) } end return nil end