Class: ZLocalize::ConditionalExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/zlocalize/source_parser.rb

Overview

represents an ‘inline-if’ expression, as in:

something ? when_true : when_false

Instance Attribute Summary collapse

Attributes inherited from Expression

#char_no, #line_no, #sub_method, #text

Instance Method Summary collapse

Methods inherited from Expression

#is_translate_call, #prefix, #set_text

Constructor Details

#initialize(line_to, char_no) ⇒ ConditionalExpression

Returns a new instance of ConditionalExpression.



303
304
305
# File 'lib/zlocalize/source_parser.rb', line 303

def initialize(line_to,char_no)
  super(line_to,char_no,'?')
end

Instance Attribute Details

#conditionObject

:nodoc: all



299
300
301
# File 'lib/zlocalize/source_parser.rb', line 299

def condition
  @condition
end

#false_exprObject

Returns the value of attribute false_expr.



301
302
303
# File 'lib/zlocalize/source_parser.rb', line 301

def false_expr
  @false_expr
end

#true_exprObject

Returns the value of attribute true_expr.



300
301
302
# File 'lib/zlocalize/source_parser.rb', line 300

def true_expr
  @true_expr
end

Instance Method Details

#display(indent = 0) ⇒ Object



307
308
309
310
311
312
313
314
315
316
# File 'lib/zlocalize/source_parser.rb', line 307

def display(indent = 0)
  i = prefix(indent) + "#{self.class.name} (#{line_no},#{char_no})\n"
  i << prefix(indent+1) + "condition:\n"
  i << @condition.display(indent+2)
  i << prefix(indent+1) + "when true:\n"
  i << @true_expr.display(indent+2)
  i << prefix(indent+1) + "when false:\n"
  i << @false_expr.display(indent+2)
  i
end

#to_entry_stringObject



324
325
326
# File 'lib/zlocalize/source_parser.rb', line 324

def to_entry_string
  "#{conditions.as_entry_string} ? #{true_expr.as_entry_string} : #{false_expr.as_entry_string}".force_encoding("UTF-8")
end

#to_translation_entry(filename) ⇒ Object



318
319
320
321
322
# File 'lib/zlocalize/source_parser.rb', line 318

def to_translation_entry(filename)
  [condition.to_translation_entry(filename),
   true_expr.to_translation_entry(filename),
   false_expr.to_translation_entry(filename)].flatten.compact
end