smartdict-core 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -19,7 +19,7 @@ module Smartdict::Drivers
19
19
  USER_AGENT = "Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.1.16) Gecko/20110429 Iceweasel/3.5.16 (like Firefox/3.5.1623123)"
20
20
 
21
21
  # Host of Lingvo service.
22
- HOST = "lingvo.yandex.ru"
22
+ HOST = "slovari.yandex.ru"
23
23
 
24
24
  # Mapping for word classes. Default is "other"
25
25
  WORD_CLASSES = {
@@ -43,22 +43,23 @@ module Smartdict::Drivers
43
43
  def translate
44
44
  doc = Nokogiri::HTML(get_response)
45
45
 
46
- if main_div = doc.css("div.b-translate > div.b-translate__value > ul > li#I").first
47
- translate__value = main_div
46
+ if main = doc.css("div.b-translation__article > ul > li#I").first
48
47
  else
49
- main_div = doc.css("div.b-translate").first
50
- translate__value = main_div.css("div.b-translate__value")
48
+ main = doc.css("div.b-translation__article").first
51
49
  end
52
50
 
51
+ raise Smartdict::TranslationNotFound unless main
52
+
53
53
  # Fetch transcription
54
- self.transcription = main_div.xpath('(.//span[@class="b-translate__tr"])[1]').try(:text)
54
+ self.transcription = doc.css("span.b-translation__tr").first.try(:text)
55
+
55
56
 
56
57
  self.translated = {}
57
58
 
58
- if translate__value.xpath("./i/acronym").any?
59
- grep_meanings(translate__value)
59
+ if main.xpath("./i/acronym").any?
60
+ grep_meanings(main)
60
61
  else
61
- translate__value.xpath("./ul/li").each do |li|
62
+ main.xpath("./ul/li").each do |li|
62
63
  grep_meanings(li)
63
64
  end
64
65
  end
@@ -66,11 +67,15 @@ module Smartdict::Drivers
66
67
 
67
68
  # TODO: refactor
68
69
  def grep_meanings(html_element)
70
+ require 'pry'
71
+ #binding.pry
72
+
69
73
  acronym = html_element.css("acronym").first
70
74
  return unless acronym
71
75
 
72
76
  ru_word_class = acronym["title"]
73
77
  word_class = WORD_CLASSES[ru_word_class]
78
+ puts word_class
74
79
  translations = []
75
80
 
76
81
  html_element.css("ul > li").each do |tr|
@@ -122,13 +127,12 @@ module Smartdict::Drivers
122
127
  # @return [String] http path for request to translate word.
123
128
  def http_path
124
129
  phrase = case [from_lang, to_lang]
125
- when ["en", "ru"] then "с английского"
126
- # ru -> en does not seem to be good and it's not trivial to parse
127
- # when ["ru", "en"] then "по-английски"
130
+ when ["en", "ru"] then "en-ru"
131
+ when ["ru", "en"] then "ru-en"
128
132
  else raise Smartdict::TranslationNotFound
129
133
  end
130
134
 
131
- "/#{escape(word)}/#{escape(phrase)}/"
135
+ "/#{escape(word)}/#{phrase}/"
132
136
  end
133
137
 
134
138
  def escape(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartdict-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-10 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dm-core