Module: Fbe::Award::PTerm
- Defined in:
- lib/fbe/award.rb
Overview
A term for bylaw.
Instance Method Summary collapse
- #abstract? ⇒ Boolean
- #publish_to(bylaw) ⇒ Object
- #static? ⇒ Boolean
- #to_p(any) ⇒ Object
-
#to_s ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity.
Instance Method Details
#abstract? ⇒ Boolean
268 269 270 |
# File 'lib/fbe/award.rb', line 268 def abstract? false end |
#publish_to(bylaw) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/fbe/award.rb', line 272 def publish_to(bylaw) case @op when :award @operands.each do |o| o.publish_to(bylaw) rescue StandardError => e raise(Fbe::Error, "Failure in #{o}: #{e.}") end when :aka @operands[0..-2].each do |o| o.publish_to(bylaw) rescue StandardError => e raise(Fbe::Error, "Failure in #{o}: #{e.}") end bylaw.revert(@operands.size - 1) bylaw.line(to_p(@operands[-1])) when :explain bylaw.intro(to_p(@operands[0])) when :in bylaw.line("assume that #{to_p(@operands[0])} is #{to_p(@operands[1])}") when :let bylaw.line("let #{to_p(@operands[0])} be equal to #{to_p(@operands[1])}") bylaw.let(@operands[0], @operands[1]) when :set bylaw.line("set #{to_p(@operands[0])} to #{to_p(@operands[1])}") when :give bylaw.line("award #{to_p(@operands[0])}") else raise(Fbe::Error, "Unknown term '#{@op}'") end end |
#static? ⇒ Boolean
264 265 266 |
# File 'lib/fbe/award.rb', line 264 def static? true end |
#to_p(any) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/fbe/award.rb', line 304 def to_p(any) case any when PTerm any.to_s when Symbol s = any.to_s subs = { 0 => '₀', 1 => '₁', 2 => '₂', 3 => '₃', 4 => '₄', 5 => '₅', 6 => '₆', 7 => '₇', 8 => '₈', 9 => '₉' } s.gsub!(/([a-z]+)([0-9])/) { |_| "#{Regexp.last_match[1]}#{subs[Integer(Regexp.last_match[2], 10)]}" } "_#{s.tr('_', '-')}_" when Integer, Float "**#{any}**" else any end end |
#to_s ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/fbe/award.rb', line 223 def to_s # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity case @op when :total 'total' when :if "if #{to_p(@operands[0])} then #{to_p(@operands[1])} else #{to_p(@operands[2])}" when :and @operands.join(' and ') when :or @operands.join(' or ') when :not "not #{@operands[0]}" when :eq "#{to_p(@operands[0])} = #{to_p(@operands[1])}" when :lt "#{to_p(@operands[0])} < #{to_p(@operands[1])}" when :lte "#{to_p(@operands[0])} ≤ #{to_p(@operands[1])}" when :gt "#{to_p(@operands[0])} > #{to_p(@operands[1])}" when :gte "#{to_p(@operands[0])} ≥ #{to_p(@operands[1])}" when :div "#{to_p(@operands[0])} ÷ #{to_p(@operands[1])}" when :times "#{to_p(@operands[0])} × #{to_p(@operands[1])}" when :plus "#{to_p(@operands[0])} + #{to_p(@operands[1])}" when :minus "#{to_p(@operands[0])} - #{to_p(@operands[1])}" when :max "maximum of #{to_p(@operands[0])} and #{to_p(@operands[1])}" when :min "minimum of #{to_p(@operands[0])} and #{to_p(@operands[1])}" when :between "#{to_p(@operands[0])} clamped between #{to_p(@operands[1])} and #{to_p(@operands[2])}" else raise(Fbe::Error, "Unknown term '#{@op}'") end end |