-
-
Save k1ife/2be99c7efdba14d097009b96a38e4f1c to your computer and use it in GitHub Desktop.
Model for work with http://morpher.ru/ service
This file contains 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
Usage example: | |
>> text = Morpher.new('Большой город') | |
{:Р=>"Большого города", :Д=>"Большому городу", :В=>"Большой город", :Т=>"Большим городом", :П=>"Большом городе", :П_о=>"о Большом городе", :род=>"Мужской", :множественное=>{:И=>"Большие города", :Р=>"Больших городов", :Д=>"Большим городам", :В=>"Большие города", :Т=>"Большими городами", :П=>"Больших городах", :П_о=>"о Больших городах"}, :где=>"в Большом городе", :куда=>"в Большой город", :откуда=>"из Большого города"} | |
>> text.singular('Д') | |
"Большому городу" | |
>> text.plural('Д') | |
"Большим городам" | |
>> text.singular('П_о') | |
"о Большом городе" | |
>> text.singular('где') | |
"в Большом городе" | |
>> text.singular('куда') | |
"в Большой город" | |
>> text.singular('откуда') | |
"из Большого города" | |
>> text.singular('род') | |
"Мужской" |
This file contains 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
# encoding: utf-8 | |
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[:множественное] ? @data[:множественное][padeg.to_sym] : nil | |
end | |
private | |
def header | |
{ | |
'Credentials' => { | |
'Username' => 'your_username', | |
'Password' => 'your_password' | |
}, | |
: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