class I18n::Magic::Entity::TranslationRecord

Attributes

key[R]
value[R]

Public Class Methods

new(key, value) click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 9
def initialize(key, value)
  @key = key
  @value = value
  clean
  prepare_key
end

Public Instance Methods

as_string_row() click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 20
def as_string_row
  "  #{@key}: #{@value}"
end
valid?() click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 16
def valid?
  @key.present? && @value.present? && !@key.empty? && !@value.empty?
end

Private Instance Methods

clean() click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 26
def clean
  @key = @key.to_s.strip
  @value = @value.to_s.strip
  @value = "'#{@value}'" if !@value.start_with?('\'') && value_has_variable?
end
prepare_key() click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 32
def prepare_key
  @key = (@key[1..-1]).strip if @key.start_with?(':')
  @key = I18n::Magic::Helpers::StringOps.underscore(@key)
end
value_has_variable?() click to toggle source
# File lib/i18n/magic/entity/translation_record.rb, line 37
def value_has_variable?
  @value.include?('%{') && (@value.index('}', @value.index('%{')) || -1).positive?
end