google-translate 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -29,6 +29,6 @@
29
29
 
30
30
  * Reflecting changes in how google returns supported languages list
31
31
 
32
- == Version 0.6.3
32
+ == Version 0.6.7
33
33
 
34
34
  * Deploy on gemcutter
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.6
1
+ 0.6.7
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{google-translate}
8
- s.version = "0.6.6"
8
+ s.version = "0.6.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Shvets"]
12
- s.date = %q{2010-04-29}
12
+ s.date = %q{2010-05-04}
13
13
  s.description = %q{Simple client for Google Translate API.}
14
14
  s.email = %q{alexander.shvets@gmail.com}
15
15
  s.executables = ["translate", "t"]
@@ -98,8 +98,8 @@ module Google
98
98
  open(URI.escape(request)) do |stream|
99
99
  content = stream.read
100
100
 
101
- from_languages = collect_languages content, 'sllangdropdown', 'sl', 'old_sl'
102
- to_languages = collect_languages content, 'tllangdropdown', 'tl', 'old_tl'
101
+ from_languages = collect_languages content, 0, 'sllangdropdown', 'sl', 'old_sl'
102
+ to_languages = collect_languages content, 1, 'tllangdropdown', 'tl', 'old_tl'
103
103
 
104
104
  response[:from_languages] = from_languages
105
105
  response[:to_languages] = to_languages
@@ -108,7 +108,7 @@ module Google
108
108
  response
109
109
  end
110
110
 
111
- def collect_languages buffer, class_name, tag_name, tag_id
111
+ def collect_languages buffer, index, class_name, tag_name, tag_id
112
112
  languages = []
113
113
 
114
114
  spaces = '\s?'
@@ -116,17 +116,23 @@ module Google
116
116
 
117
117
  class_part = "class#{spaces}=#{spaces}#{quote}#{class_name}#{quote}"
118
118
  name_part = "name#{spaces}=#{spaces}#{quote}#{tag_name}#{quote}"
119
- id_part = "id#{spaces}=#{spaces}#{quote}old_sl#{quote}"
119
+ id_part = "id#{spaces}=#{spaces}#{quote}#{tag_id}#{quote}"
120
120
  tabindex_part = "tabindex#{spaces}=#{spaces}#{quote}0#{quote}"
121
-
122
121
  re1 = buffer.split(%r{<select#{spaces}#{class_part}#{spaces}#{name_part}#{spaces}#{id_part}#{spaces}#{tabindex_part}#{spaces}>(.*)?</select>}).select{|x| x =~ %r{<option} }
123
- text = re1[0]
124
122
 
125
- re2 = /<option(\s*)value="([a-z|A-Z]*)">([a-z|A-Z]*)<\/option>/
123
+ text = re1[index]
124
+
125
+ if index == 0
126
+ pos = text.index('</select><span class=langselect')
127
+ text = text[0..pos]
128
+ end
129
+
130
+ re2 = /<option(\s*)value="([a-z|A-Z|-]*)">([a-z|A-Z|\(|\)|\s]*)<\/option>/
126
131
 
127
- matches = text.scan(re2)
132
+ matches = text.gsub(/selected/i, '').squeeze.scan(re2)
128
133
 
129
134
  matches.each do |m|
135
+ p m[1]
130
136
  languages << Language.new(m[2], m[1])
131
137
  end
132
138
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 6
9
- version: 0.6.6
8
+ - 7
9
+ version: 0.6.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexander Shvets
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-29 00:00:00 -04:00
17
+ date: 2010-05-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency