-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhurra.rb
More file actions
78 lines (65 loc) · 1.62 KB
/
hurra.rb
File metadata and controls
78 lines (65 loc) · 1.62 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/ruby
require 'nokogiri'
require 'open-uri'
require 'colorize'
def clean_print(t,ind)
t.each_line do |line|
line.strip!
puts (" "*ind).concat line if line!=""
end
end
def print_example(pair,ind)
puts (" "*ind).concat pair.css('.eg').text.green.bold # green
clean_print(pair.css('.hdb').text,ind)
puts
end
def print_sense(body)
body.css('> div.def-block').each do |blk|
print_def(blk,0) if !blk.classes.include?('ddef_block-nos')
end
body.css('.phrase-block').each do |blk|
print_phrase(blk)
end
end
def print_def(defi,ind)
puts (" "*ind).concat defi.css('.def-head').text if defi.css('.def-head').text !=""
puts (" "*ind).concat defi.css('.def-body').css('> span.trans').text.red #read
puts
defi.css('.def-body').css('.examp').each do |pair|
print_example(pair,ind + 2)
end
end
def print_phrase(blk)
puts blk.css('.phrase-head').text.gsub(/^[[:space:]]+/, '').light_blue
blk.css('.def-block').each do |d|
print_def(d, 2)
end
end
def print_di(di)
puts "----".cyan.bold
head = di.css('.di-head')
body = di.css('.di-body')
puts head.css('.di-title').text
puts head.css('.di-info').text
puts
body.css('.sense-body').each do |blk|
print_sense(blk)
end
end
word = ARGV[0].dup
word.gsub! 'ą','a'
word.gsub! 'ć','c'
word.gsub! 'ę','e'
word.gsub! 'ł','l'
word.gsub! 'ń','n'
word.gsub! 'ś','s'
word.gsub! 'ź','z'
word.gsub! 'ż','z'
word.gsub! 'ó','o'
u = 'https://dictionary.cambridge.org/us/dictionary/polish-english/'.concat(word)
doc = Nokogiri::HTML(open(u))
puts `clear`
entry = doc.css('.dictionary')[0]
entry.css('.di').each do |di|
print_di(di)
end