Class: RMathGuard::Expression
- Inherits:
-
Object
- Object
- RMathGuard::Expression
- Defined in:
- lib/rmathguard/expression.rb
Constant Summary collapse
- OPERANDS =
%w[ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE]
- OPERATORS =
{"+" => "PLUS", "-" => "MINUS"}
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Expression
constructor
A new instance of Expression.
- #show ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Expression
Returns a new instance of Expression.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rmathguard/expression.rb', line 9 def initialize( = {}) @max_value = [:max_value] || 10 @row_count = [:row_count] || 5 @col_count = [:col_count] || [:column_count] || 3 @sep_size = [:sep_size] || 2 @negative = [:negative] || false unless @row_count == 5 && @col_count == 3 RMathGuard::Numbers.resize(@row_count, @col_count) RMathGuard::Operators.resize(@row_count, @col_count) end generate end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/rmathguard/expression.rb', line 7 def result @result end |
Instance Method Details
#show ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rmathguard/expression.rb', line 23 def show n = RMathGuard::Numbers op1 = n.const_get(OPERANDS[@operand1]).masked op2 = n.const_get(OPERANDS[@operand2]).masked o = RMathGuard::Operators sign = o.const_get(OPERATORS[@operator]).masked eq = o::EQUALS.masked result = [] (0...@row_count).each do |row| result[row] = [] result[row] << op1[row] @sep_size.times { result[row] << 0 } result[row] << sign[row] @sep_size.times { result[row] << 0 } result[row] << op2[row] @sep_size.times { result[row] << 0 } result[row] << eq[row] result[row].flatten! end result.map { |row| row.join("") }.join("\n").tr("0", " ") end |