Class: RBlade::CompilesStatements::CompilesConditionals

Inherits:
Object
  • Object
show all
Defined in:
lib/rblade/compiler/statements/compiles_conditionals.rb

Instance Method Summary collapse

Instance Method Details

#compileCase(args) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 36

def compileCase args
  if args&.count != 1
    raise StandardError.new "Case statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "case #{args[0]};"
end

#compileChecked(args) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 52

def compileChecked args
  if args&.count != 1
    raise StandardError.new "Checked statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};_out<<'checked';end;"
end

#compileDisabled(args) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 60

def compileDisabled args
  if args&.count != 1
    raise StandardError.new "Disabled statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};_out<<'disabled';end;"
end

#compileElse(args) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 20

def compileElse args
  if !args.nil?
    raise StandardError.new "Else statement: wrong number of arguments (given #{args&.count || 0}, expecting 0)"
  end

  "else;"
end

#compileElsif(args) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 12

def compileElsif args
  if args&.count != 1
    raise StandardError.new "Elsif statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "elsif #{args[0]};"
end

#compileIf(args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 4

def compileIf args
  if args&.count != 1
    raise StandardError.new "If statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};"
end

#compileReadonly(args) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 68

def compileReadonly args
  if args&.count != 1
    raise StandardError.new "Readonly statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};_out<<'readonly';end;"
end

#compileRequired(args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 76

def compileRequired args
  if args&.count != 1
    raise StandardError.new "Required statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};_out<<'required';end;"
end

#compileSelected(args) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 84

def compileSelected args
  if args&.count != 1
    raise StandardError.new "Selected statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "if #{args[0]};_out<<'selected';end;"
end

#compileUnless(args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 28

def compileUnless args
  if args&.count != 1
    raise StandardError.new "Unless statement: wrong number of arguments (given #{args&.count || 0}, expecting 1)"
  end

  "unless #{args[0]};"
end

#compileWhen(args) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/rblade/compiler/statements/compiles_conditionals.rb', line 44

def compileWhen args
  if args.nil? || args.count == 0
    raise StandardError.new "When statement: wrong number of arguments (given #{args&.count || 0}, expecting at least 1)"
  end

  "when #{args.join ","};"
end