-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlmn
More file actions
executable file
·58 lines (41 loc) · 794 Bytes
/
lmn
File metadata and controls
executable file
·58 lines (41 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/env ruby
require 'rest-client'
require 'json'
require_relative 'timer'
class Query
URL = 'http://api.pearson.com/v2/dictionaries/ldoce5/entries'
attr_reader :resp, :json, :word
def initialize word
@word = word
@resp = RestClient.get URL, {params: {headword: word}}
end
def to_str
"#{word} [#{ipa}]\n#{explains.map{|ex| '-> ' + ex}.join("\n")}"
end
private
def ipa
results[0]['pronunciations'][0]['ipa']
rescue
nil
end
def json
@json ||= JSON.parse(resp.body)
end
def results
json['results']
end
def explains
results.map do |rs|
rs['senses'][0]['definition'][0]
end
rescue
[]
end
end
# main
timer do
result = ARGV.map do |arg|
Query.new(arg)
end
puts result.join("\n\n")
end