Mistři v programování na #hovnokod

Ruby #311

module ModelHelper
  extend ActiveSupport::Concern

  module InstanceMethods

    def prepare_url
      "http://#{Banjo::Application.config.short_url_host}"
    end

    def adjust_comment(text, url, max_len)
      maximum_text_length = max_len - url.length - 1
      if text.length > maximum_text_length
        text = text[0, maximum_text_length - 3] + "..."
      end
      if url.present?
        message = [text, url].join(' ')
      else
        message = text
      end
      message
    end

    def fullname_to_first_last_initial(fullname)
      name_token = fullname.split(/ /)
      last_initial = (name_token.length > 1) ? name_token.pop.first : nil
      first = name_token.join(' ')
      return (last_initial.nil?) ? first : "#{first} #{last_initial}"
    end

  end

  module ClassMethods

    def adjust_comment(text, url, max_len)
      maximum_text_length = max_len - url.length - 1
      if text.length > maximum_text_length
        text = text[0, maximum_text_length - 3] + "..."
      end
      if url.present?
        message = [text, url].join(' ')
      else
        message = text
      end
      message
    end

    def fullname_to_first_last_initial(fullname)
      name_token = fullname.split(/ /)
      last_initial = (name_token.length > 1) ? name_token.pop.first : nil
      first = name_token.join(' ')
      return (last_initial.nil?) ? first : "#{first} #{last_initial}"
    end

  end

end

HovnoKod,