Sha256: 0b38781cf988d6e518b7dd4e2054435887818e05c6b419a591d927ba7d170493

Contents?: true

Size: 859 Bytes

Versions: 12

Compression:

Stored size: 859 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)
        if match = token.value.match(/([\s]*)'(.*)'([\s]*)/)
          match.captures.join
        else
          token.value
        end
      end

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

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
twitter_cldr-3.1.0 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.10 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.9 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.8 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.7 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.6 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.5 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.4 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.3 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.2 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.1 lib/twitter_cldr/formatters/formatter.rb
twitter_cldr-3.0.0 lib/twitter_cldr/formatters/formatter.rb