Skip to content

Instantly share code, notes, and snippets.

@leemour
Created June 21, 2016 12:59
Show Gist options
  • Save leemour/8f2320ca693c9b545b73624d0709c6a6 to your computer and use it in GitHub Desktop.
Save leemour/8f2320ca693c9b545b73624d0709c6a6 to your computer and use it in GitHub Desktop.
Morpher ruby склонение по падежам
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