Sha256: 016fbe2f62c257bc87d6563a8c434400fb9cbbf66456d4cccba30ea2f354e84c

Contents?: true

Size: 738 Bytes

Versions: 11

Compression:

Stored size: 738 Bytes

Contents

module Martyr
  module Translations

    def with_standard_id(id)
      x, y = id_components(id)
      y.nil? ? yield(id.to_s) : yield(x, y)
    end

    def id_components(id)
      id_s = id.to_s
      id_s.split('.')
    end

    def first_element_from_id(id)
      id.to_s.include?('.') ? id.to_s.split('.').first : id.to_s
    end

    # @param id [String]
    # @option fallback [Boolean] if true, will return the id if only one element exists in the id
    def second_element_from_id(id, fallback: false)
      if id.to_s.include?('.')
        id.to_s.split('.').last
      else
        fallback ? id.to_s : nil
      end
    end

    def to_id(object)
      return object if object.is_a?(String)
      object.id
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
martyr-0.1.85.pre lib/martyr/helpers/translations.rb
martyr-0.1.84.pre lib/martyr/helpers/translations.rb
martyr-0.1.82.pre lib/martyr/helpers/translations.rb
martyr-0.1.81.pre lib/martyr/helpers/translations.rb
martyr-0.1.80.pre lib/martyr/helpers/translations.rb
martyr-0.1.79.pre lib/martyr/helpers/translations.rb
martyr-0.1.78.pre lib/martyr/helpers/translations.rb
martyr-0.1.77.pre lib/martyr/helpers/translations.rb
martyr-0.1.76.pre lib/martyr/helpers/translations.rb
martyr-0.1.75.pre lib/martyr/helpers/translations.rb
martyr-0.1.74.pre lib/martyr/helpers/translations.rb