module TextHyphenRails::ActiveRecordExtension::ClassMethods
Public Instance Methods
html_hyphen(*args, **opts)
click to toggle source
# File lib/text_hyphen_rails/active_record_extension.rb, line 17 def html_hyphen(*args, **opts) thr_create_methods(HtmlHyphenator, args, opts) end
text_hyphen(*args, **opts)
click to toggle source
# File lib/text_hyphen_rails/active_record_extension.rb, line 13 def text_hyphen(*args, **opts) thr_create_methods(TextHyphenator, args, opts) end
Private Instance Methods
thr_create_methods(h_class, args, opts)
click to toggle source
# File lib/text_hyphen_rails/active_record_extension.rb, line 23 def thr_create_methods(h_class, args, opts) args.each do |att| m_opts = thr_m_opts att, opts self.send(:define_method, thr_meth_name(att, m_opts)) do str = read_attribute att lang = _thr_lang m_opts h_class.new(str, lang, m_opts).result end self.send(:define_method, "#{att}_orig") { read_attribute att } if opts[:replace_meth] end end
thr_m_opts(meth, opts)
click to toggle source
# File lib/text_hyphen_rails/active_record_extension.rb, line 44 def thr_m_opts(meth, opts) raise UnknownOptionError if (opts.keys - TextHyphenRails.settings.keys).size > 0 TextHyphenRails.settings.merge opts end
thr_meth_name(att, opts)
click to toggle source
# File lib/text_hyphen_rails/active_record_extension.rb, line 36 def thr_meth_name(att, opts) if opts[:replace_meth] att else [opts[:prefix], att, opts[:suffix]].reject(&:nil?).join('_') end end