Sha256: cdaba7e52ac6b5cb41f8190c1f77d1d679770105b3e49aeb2c238de67c9ac135

Contents?: true

Size: 818 Bytes

Versions: 24

Compression:

Stored size: 818 Bytes

Contents

# encoding: UTF-8

# Copyright 2012 Twitter, Inc
# http://www.apache.org/licenses/LICENSE-2.0

module TwitterCldr
  module Formatters
    class Formatter

      attr_reader :data_reader

      def initialize(data_reader)
        @data_reader = data_reader
      end

      def format(tokens, obj, options = {})
        tokens.each_with_index.inject("") do |ret, (token, index)|
          method_sym = :"format_#{token.type}"
          ret << send(method_sym, token, index, obj, options)
        end
      end

      protected

      def format_plaintext(token, index, obj, options)
        token.value.gsub(/'([^']+)'/, '\1') # remove single-quote escaping for "real" characters
      end

      def format_composite(token, index, obj, options)
        eval(format(token.tokens, obj)).to_s
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/formatters/formatter.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/twitter_cldr-4.4.5/lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.5 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.4 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.3 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.2 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.1 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.4.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.3.1 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.3.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.2.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.1.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-4.0.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.6.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.5.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.4.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.3.0 lib/twitter_cldr/formatters/formatter.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/formatters/formatter.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/twitter_cldr-3.2.1/lib/twitter_cldr/formatters/formatter.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/twitter_cldr-3.1.2/lib/twitter_cldr/formatters/formatter.rb