Created
June 21, 2016 12:59
-
-
Save leemour/8f2320ca693c9b545b73624d0709c6a6 to your computer and use it in GitHub Desktop.
Morpher ruby склонение по падежам
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'savon' | |
class Morpher | |
def initialize(phrase) | |
client = Savon.client do |globals| | |
globals.wsdl 'http://morpher.ru/WebService.asmx?WSDL' | |
globals.soap_version 2 | |
globals.soap_header header | |
end | |
response = client.call(:get_xml, | |
message: { | |
s: phrase | |
}, | |
attributes: { | |
xmlns: 'http://morpher.ru/' | |
} | |
) | |
@data = response.to_array(:get_xml_response, :get_xml_result).first | |
end | |
def singular(padeg) | |
@data[padeg.to_sym] | |
end | |
def plural(padeg) | |
@data[:множественное][padeg.to_sym] | |
end | |
private | |
def header | |
{ | |
'Credentials' => { | |
'Username' => 'test', | |
'Password' => 'test' | |
}, | |
:attributes! => { | |
'Credentials' => { | |
:xmlns => 'http://morpher.ru/' | |
} | |
} | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment