Sha256: 16d97845692aeee1488e5b20839540a1928ce82e0e035063067f6318e6748aa4

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 Bytes

Contents

# frozen_string_literal: true

module I18n::Tasks::Scanners
  module RubyKeyLiterals
    LITERAL_RE = /:?".+?"|:?'.+?'|:\w+/.freeze

    # Match literals:
    # * String: '', "#{}"
    # * Symbol: :sym, :'', :"#{}"
    def literal_re
      LITERAL_RE
    end

    # remove the leading colon and unwrap quotes from the key match
    # @param literal [String] e.g: "key", 'key', or :key.
    # @return [String] key
    def strip_literal(literal)
      literal = literal[1..-1] if literal[0] == ':'
      literal = literal[1..-2] if literal[0] == "'" || literal[0] == '"'
      literal
    end

    VALID_KEY_CHARS = /(?:[[:word:]]|[-.?!:;À-ž])/.freeze
    VALID_KEY_RE    = /^#{VALID_KEY_CHARS}+$/.freeze

    def valid_key?(key)
      key =~ VALID_KEY_RE && !key.end_with?('.')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n-tasks-0.9.35 lib/i18n/tasks/scanners/ruby_key_literals.rb
i18n-tasks-0.9.34 lib/i18n/tasks/scanners/ruby_key_literals.rb