Class: ZLocalize::ConditionalExpression

Inherits:
Expression
  • Object
show all
Defined in:
lib/zlocalize/rdoc_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.



307
308
309
# File 'lib/zlocalize/rdoc_source_parser.rb', line 307

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

Instance Attribute Details

#conditionObject

:nodoc: all



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

def condition
  @condition
end

#false_exprObject

Returns the value of attribute false_expr.



305
306
307
# File 'lib/zlocalize/rdoc_source_parser.rb', line 305

def false_expr
  @false_expr
end

#true_exprObject

Returns the value of attribute true_expr.



304
305
306
# File 'lib/zlocalize/rdoc_source_parser.rb', line 304

def true_expr
  @true_expr
end

Instance Method Details

#display(indent = 0) ⇒ Object



311
312
313
314
315
316
317
318
319
320
# File 'lib/zlocalize/rdoc_source_parser.rb', line 311

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



328
329
330
# File 'lib/zlocalize/rdoc_source_parser.rb', line 328

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



322
323
324
325
326
# File 'lib/zlocalize/rdoc_source_parser.rb', line 322

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