Sha256: 4f760b28a6d3b89b35b327f6e86ed2c41391a62994b1861d01b7b0b76a8e0337

Contents?: true

Size: 800 Bytes

Versions: 1

Compression:

Stored size: 800 Bytes

Contents

# encoding: UTF-8

module Rosette
  module Core

    # Turns a {Translation} into a hash. Must be mixed into a {Translation}-like
    # class.
    #
    # @example
    #   t = Translation.new
    #   t.translation = 'foó'
    #   t.locale = 'fr-FR'
    #   t.phrase = Phrase.new
    #
    #   t.to_h  # => { translation: 'foó', locale: 'fr-FR', phrase: { ... } }
    module TranslationToHash
      # Converts the attributes of a {Translation} into a hash of attributes.
      # This includes the attributes of the associated {Phrase} object, which
      # is also converted to a hash via the {PhraseToHash} module.
      #
      # @return [Hash] a hash of translation attributes.
      def to_h
        { locale: locale, translation: translation, phrase: phrase.to_h }
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rosette-core-1.0.1 lib/rosette/core/extractor/translation/translation_to_hash.rb