Module: XlsFunction::FormatString::TransformRules::Numbers
- Included in:
- XlsFunction::FormatString::Transform
- Defined in:
- lib/xls_function/format_string/transform_rules/numbers.rb
Defined Under Namespace
Modules: DigitConcern
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xls_function/format_string/transform_rules/numbers.rb', line 5 def self.included(klass) klass.class_eval do rule(digit_s: simple(:digit_s)) do (->(input) do s = input.to_s s == '0' ? '' : s end).tap do |p| p.extend DigitConcern end end rule(digit_z: simple(:digit_z)) do (->(input) do s = input.to_s s != '' ? s : '0' end).tap do |p| p.extend DigitConcern end end rule(digit_q: simple(:digit_q)) do (->(input) do s = input.to_s s != '' ? s : ' ' end).tap do |p| p.extend DigitConcern end end rule(number: subtree(:number)) { number } # 1 number and 1 suffix patterns such as '0%' rule(number: subtree(:number), string: simple(:string)) do [number, ->(_) { string }] end rule(texts: subtree(:texts), number: subtree(:number)) do [texts, number] end rule(numbers: subtree(:numbers)) do ::XlsFunction::FormatString::Evaluators::NumberEvaluator.new(Array(numbers).flatten) end end end |