class Tr8n::TokenizedLabel

Public Class Methods

new(label) click to toggle source

constracts the label

# File lib/tr8n/tokenized_label.rb, line 28
def initialize(label)
  @label = label
end

Public Instance Methods

allowed_token?(token) click to toggle source
# File lib/tr8n/tokenized_label.rb, line 129
def allowed_token?(token)
  not sanitized_tokens_hash[token.sanitized_name].nil?
end
data_tokens() click to toggle source

scans for all token types

# File lib/tr8n/tokenized_label.rb, line 37
def data_tokens
  @data_tokens ||= Tr8n::Token.register_data_tokens(label)
end
data_tokens?() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 41
def data_tokens?
  data_tokens.any?
end
decoration_tokens() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 45
def decoration_tokens
  @decoration_tokens ||= Tr8n::Token.register_decoration_tokens(label)
end
decoration_tokens?() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 49
def decoration_tokens?
  decoration_tokens.any?
end
label() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 32
def label
  @label
end
sanitized_label() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 80
def sanitized_label
  @sanitized_label ||= begin 
    lbl = label.clone
    data_tokens.each do |token|
      lbl = token.prepare_label_for_translator(lbl)
    end
    lbl
  end 
end
sanitized_tokens_hash() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 57
def sanitized_tokens_hash
  @sanitized_tokens_hash ||= begin
    hash = {}
    tokens.each do |token|
      hash[token.sanitized_name] = token
    end
    hash
  end
end
suggestion_tokens() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 100
def suggestion_tokens
  @suggestion_tokens ||= begin
    toks = []
    tokens.each do |token|
      if token.decoration?
        toks << token.name
      else  
        toks << token.sanitized_name          
      end
    end
    toks
  end
end
tokenless_label() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 90
def tokenless_label
  @tokenless_label ||= begin
    lbl = label.clone
    tokens.each_with_index do |token, index|
      lbl = token.prepare_label_for_suggestion(lbl, index)
    end
    lbl
  end
end
tokens() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 53
def tokens
  @tokens = data_tokens + decoration_tokens
end
tokens?() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 67
def tokens?
  tokens.any?
end
translation_tokens() click to toggle source

tokens that can be used by the user in translation

# File lib/tr8n/tokenized_label.rb, line 72
def translation_tokens
  @translation_tokens ||= tokens.select{|token| token.allowed_in_translation?} 
end
translation_tokens?() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 76
def translation_tokens?
  translation_tokens.any?
end
words() click to toggle source
# File lib/tr8n/tokenized_label.rb, line 114
def words
  return [] if label.blank?

  @words ||= begin 
    clean_label = sanitized_label
    parts = []
    clean_label = clean_label.gsub(/[\,\.\;\!\-\:\'\"\[\]{}]/, "")
  
    clean_label.split(" ").each do |w|
      parts << w.strip.capitalize if w.length > 3
    end
    parts
  end
end