Class: Fbe::Award::PTerm
- Inherits:
-
Object
- Object
- Fbe::Award::PTerm
- Defined in:
- lib/fbe/award.rb
Overview
A term for policy.
Instance Method Summary collapse
-
#initialize(operator, operands) ⇒ PTerm
constructor
A new instance of PTerm.
- #publish_to(policy) ⇒ Object
- #to_s ⇒ Object
- #to_str(any) ⇒ Object
Constructor Details
#initialize(operator, operands) ⇒ PTerm
Returns a new instance of PTerm.
138 139 140 141 |
# File 'lib/fbe/award.rb', line 138 def initialize(operator, operands) @op = operator @operands = operands end |
Instance Method Details
#publish_to(policy) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/fbe/award.rb', line 178 def publish_to(policy) case @op when :award @operands.each do |o| o.publish_to(policy) rescue StandardError => e raise "Failure in #{o}: #{e.}" end when :explain policy.intro(to_str(@operands[0])) when :in policy.line("assume that #{to_str(@operands[0])} is #{to_str(@operands[1])}") when :let policy.line("let #{to_str(@operands[0])} be equal to #{to_str(@operands[1])}") when :set policy.line("set #{to_str(@operands[0])} to #{to_str(@operands[1])}") when :give policy.line("award #{to_str(@operands[0])}") else raise "Unknown term '#{@op}'" end end |
#to_s ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/fbe/award.rb', line 143 def to_s case @op when :total 'total' when :if "if #{to_str(@operands[0])} then #{to_str(@operands[1])} else #{to_str(@operands[2])}" when :eq "#{to_str(@operands[0])} == #{to_str(@operands[1])}" when :lt "#{to_str(@operands[0])} < #{to_str(@operands[1])}" when :lte "#{to_str(@operands[0])} ≤ #{to_str(@operands[1])}" when :gt "#{to_str(@operands[0])} > #{to_str(@operands[1])}" when :gte "#{to_str(@operands[0])} ≥ #{to_str(@operands[1])}" when :div "#{to_str(@operands[0])} ÷ #{to_str(@operands[1])}" when :times "#{to_str(@operands[0])} × #{to_str(@operands[1])}" when :plus "#{to_str(@operands[0])} + #{to_str(@operands[1])}" when :minus "#{to_str(@operands[0])} - #{to_str(@operands[1])}" when :max "maximum of #{to_str(@operands[0])} and #{to_str(@operands[1])}" when :min "minimum of #{to_str(@operands[0])} and #{to_str(@operands[1])}" when :between "at least #{to_str(@operands[0])} and at most #{to_str(@operands[1])}" else raise "Unknown term '#{@op}'" end end |
#to_str(any) ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/fbe/award.rb', line 201 def to_str(any) if any.is_a?(PTerm) any.to_s elsif any.is_a?(Symbol) "_#{any}_" else any end end |