Sha256: 1064c6a37f13d272a856f4f65a871382dc269ac7d2be036b03f80143daf03cb0

Contents?: true

Size: 819 Bytes

Versions: 17

Compression:

Stored size: 819 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

17 entries across 17 versions & 1 rubygems

Version Path
twitter_cldr-6.7.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.6.2 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.6.1 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.6.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.5.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.4.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.3.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.2.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.1.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.0.2 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.0.1 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-6.0.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-5.4.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-5.3.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-5.2.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-5.1.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-5.0.0 lib/twitter_cldr/formatters/formatter.rb