Class: TypografRu::Manager
- Inherits:
-
Object
- Object
- TypografRu::Manager
- Extended by:
- SingleForwardable
- Includes:
- Singleton
- Defined in:
- lib/typograf_ru/manager.rb
Instance Method Summary collapse
- #clear(klass = nil) ⇒ Object
- #exec_for(object) ⇒ Object
- #mapping ⇒ Object
- #register(klass, attr, options = {}) ⇒ Object
Instance Method Details
#clear(klass = nil) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/typograf_ru/manager.rb', line 28 def clear(klass = nil) if klass.nil? mapping.clear else mapping.delete(klass) end end |
#exec_for(object) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/typograf_ru/manager.rb', line 15 def exec_for(object) return unless mapping[object.class].is_a?(Hash) mapping[object.class].each do |attr, | next if [:if].is_a?(Proc) && ![:if].call(self) text = object.send(attr) if !text.nil? && !text.empty? && ([:no_check] || object.send("#{attr}_changed?")) res = RestClient.post('http://typograf.ru/webservice/', :text => text, :chr => 'UTF-8') object.send("#{attr}=", res.force_encoding("UTF-8")) end end end |
#mapping ⇒ Object
36 37 38 |
# File 'lib/typograf_ru/manager.rb', line 36 def mapping @mapping ||= {} end |
#register(klass, attr, options = {}) ⇒ Object
10 11 12 13 |
# File 'lib/typograf_ru/manager.rb', line 10 def register(klass, attr, = {}) mapping[klass]||= {} mapping[klass][attr] = end |