Class: SlimKeyfy::Transformer::BaseTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/slimkeyfy/transformer/base_transformer.rb

Direct Known Subclasses

ControllerTransformer, SlimTransformer

Constant Summary collapse

TRANSLATED =
/t\s*\(?\s*(".*?"|'.*?')\s*\)?/
STRING =
/(\".*\"|\'.*\')/
STRING_WITHOUT_QUOTES =
/("(?<double_quot>.*)"|'(?<single_quot>.*)')/

Instance Method Summary collapse

Constructor Details

#initialize(word, yaml_processor = nil) ⇒ BaseTransformer

Returns a new instance of BaseTransformer.



6
7
8
9
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 6

def initialize(word, yaml_processor=nil)
  @word = word
  @yaml_processor = yaml_processor
end

Instance Method Details

#controller?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 35

def controller?
  false
end

#match_string(translation) ⇒ Object



25
26
27
28
29
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 25

def match_string(translation)
  m = translation.match(STRING_WITHOUT_QUOTES)
  return translation if m.nil?
  (m[:double_quot] != nil) ? m[:double_quot] : ((m[:single_quot] != nil) ? m[:single_quot] : translation)
end

#matches_string?(translation) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 19

def matches_string?(translation)
  m = translation.match(STRING_WITHOUT_QUOTES)
  return false if m.nil?
  (m[:double_quot] != nil or m[:single_quot] != nil)
end

#nil_elemObject



11
12
13
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 11

def nil_elem
  [nil, nil]
end

#should_not_be_processed?(tokens) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 15

def should_not_be_processed?(tokens)
  (tokens.nil? or tokens.size < 2)
end

#slim?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 39

def slim?
  false
end

#update_hashes(translation) ⇒ Object



31
32
33
# File 'lib/slimkeyfy/transformer/base_transformer.rb', line 31

def update_hashes(translation)
  @word.update_translation_key_hash(@yaml_processor, translation)
end