Sha256: 9a74e9eba5d98db6b3de382441181b00c0905b98cc220e2be9689c990f87dd92

Contents?: true

Size: 470 Bytes

Versions: 10

Compression:

Stored size: 470 Bytes

Contents

class Redde::UrlGenerator
  attr_reader :id, :name
  def initialize(id, name = nil)
    @id = id
    @name = name
  end

  def url
    return "#{id}-#{formatted_name}".downcase if formatted_name.present?
    id.to_s
  end

  def translitted_name
    Russian.translit(name).gsub(' ', '-')
      .gsub(/[^\x00-\x7F]+/, '').gsub(/[^\w_ \-]+/i, '')
      .gsub(/[ \-]+/i, '-').gsub(/^\-|\-$/i, '')
  end

  def formatted_name
    name.nil? ? '' : translitted_name
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
redde-0.1.18 lib/redde/url_generator.rb
redde-0.1.17 lib/redde/url_generator.rb
redde-0.1.16 lib/redde/url_generator.rb
redde-0.1.15 lib/redde/url_generator.rb
redde-0.1.14 lib/redde/url_generator.rb
redde-0.1.13 lib/redde/url_generator.rb
redde-0.1.12 lib/redde/url_generator.rb
redde-0.1.11 lib/redde/url_generator.rb
redde-0.1.10 lib/redde/url_generator.rb
redde-0.1.9 lib/redde/url_generator.rb