Sha256: 6a96ab28ba9812ed1b6a000dd58051b724bb0fc933ff307350f515076d2c92c5

Contents?: true

Size: 493 Bytes

Versions: 2

Compression:

Stored size: 493 Bytes

Contents

# frozen_string_literal: true

require 'uri'

module Cosensee
  # parser of Bracket
  module LinkEncodable
    UNESCAPED_REGEX = /[A-Za-z0-9!"\$&'\(\)\-\~@+;:*<>,._]/

    def make_link(anchor)
      "#{encode_link(anchor)}.html"
    end

    def encode_link(str)
      str.chars.map do |char|
        if char.match?(UNESCAPED_REGEX)
          char
        elsif char == ' '
          '_'
        else
          URI.encode_www_form_component(char)
        end
      end.join
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cosensee-0.8.0 lib/cosensee/link_encodable.rb
cosensee-0.6.0 lib/cosensee/link_encodable.rb