Module: Recognition::Parser
- Defined in:
- lib/recognition/parser.rb
Class Method Summary collapse
- .parse_amount(amount, object, proc_params = nil) ⇒ Object
- .parse_code_part(part, object) ⇒ Object
- .parse_recognizable(object, recognizable, proc_params = nil) ⇒ Object
Class Method Details
.parse_amount(amount, object, proc_params = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/recognition/parser.rb', line 22 def self.parse_amount amount, object, proc_params = nil case amount.class.to_s when 'Integer' value = amount when 'Fixnum' value = amount when 'Symbol' value = object.send(amount) when 'Proc' params = proc_params || object value = amount.call(params) when 'NilClass' # Do not complain about nil amounts else raise ArgumentError, "type mismatch for amount: expecting 'Integer', 'Fixnum', 'Symbol' or 'Proc' but got '#{ amount.class.to_s }' instead." end value || 0 end |
.parse_code_part(part, object) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/recognition/parser.rb', line 41 def self.parse_code_part part, object case part.class.to_s when 'String' value = part when 'Integer' value = part.to_s when 'Fixnum' value = part.to_s when 'Symbol' value = object.send(part).to_s when 'Proc' value = part.call(object).to_s when 'NilClass' # Do not complain about nil amounts else raise ArgumentError, "type mismatch for voucher part: expecting 'Integer', 'Fixnum', 'Symbol' or 'Proc' but got '#{ amount.class.to_s }' instead." end value || '' end |
.parse_recognizable(object, recognizable, proc_params = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/recognition/parser.rb', line 3 def self.parse_recognizable object, recognizable, proc_params = nil if recognizable.nil? user = object else case recognizable.class.to_s when 'Symbol' user = object.send(recognizable) when 'String' user = object.send(recognizable.to_sym) when 'Proc' params = proc_params || object user = recognizable.call(params) else user = recognizable end end user end |