Sha256: d4f3260846c6e8ca032934c334ef3c3bc4eaaf4a5f1803086f1af5e024e6dc05

Contents?: true

Size: 719 Bytes

Versions: 18

Compression:

Stored size: 719 Bytes

Contents

require_relative 'annotation'

module SSMD::Annotations
  class LanguageAnnotation < Annotation
    attr_reader :language

    def self.regex
      /([a-z]{2}(?:-[A-Z]{2})?)/
    end

    def initialize(language)
      @language = complete_language language
    end

    def wrap(text)
      "<lang xml:lang=\"#{language}\">#{text}</lang>"
    end

    def combine(annotation)
      self # discard further language annotations
    end

    def complete_language(language)
      if language.size == 2
        language_completion_table[language] || "#{language}-#{language.upcase}"
      else
        language
      end
    end

    def language_completion_table
      {
        "en" => "en-US"
      }
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ssmd-0.7.6 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.5 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.4 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.3 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.2 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.1 lib/ssmd/annotations/language_annotation.rb
ssmd-0.7.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.6.1 lib/ssmd/annotations/language_annotation.rb
ssmd-0.6.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.5.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.4.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.3.1 lib/ssmd/annotations/language_annotation.rb
ssmd-0.3.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.2.3 lib/ssmd/annotations/language_annotation.rb
ssmd-0.2.2 lib/ssmd/annotations/language_annotation.rb
ssmd-0.2.1 lib/ssmd/annotations/language_annotation.rb
ssmd-0.2.0 lib/ssmd/annotations/language_annotation.rb
ssmd-0.1.0 lib/ssmd/annotations/language_annotation.rb