Class: Versionomy::Format::Delimiter::BasicIntegerRecognizer
- Inherits:
-
RecognizerBase
- Object
- RecognizerBase
- Versionomy::Format::Delimiter::BasicIntegerRecognizer
- Defined in:
- lib/versionomy/format/delimiter.rb
Overview
A recognizer for a numeric integer field
Instance Method Summary collapse
-
#initialize(field_, opts_ = {}) ⇒ BasicIntegerRecognizer
constructor
:nodoc:.
- #parsed_value(value_, parse_params_) ⇒ Object
- #unparsed_value(value_, style_, unparse_params_) ⇒ Object
Methods inherited from RecognizerBase
#parse, #requires_next_field, #setup, #should_unparse?, #unparse
Constructor Details
#initialize(field_, opts_ = {}) ⇒ BasicIntegerRecognizer
:nodoc:
891 892 893 894 895 |
# File 'lib/versionomy/format/delimiter.rb', line 891 def initialize(field_, opts_={}) @strip_leading_zeros = opts_[:strip_leading_zeros] @width_unparse_param_key = "#{field_.name}_width".to_sym setup(field_, '\d+', opts_) end |
Instance Method Details
#parsed_value(value_, parse_params_) ⇒ Object
897 898 899 900 901 902 903 |
# File 'lib/versionomy/format/delimiter.rb', line 897 def parsed_value(value_, parse_params_) if !@strip_leading_zeros && value_ =~ /^0\d/ [value_.to_i, {@width_unparse_param_key => value_.length}] else [value_.to_i, nil] end end |
#unparsed_value(value_, style_, unparse_params_) ⇒ Object
905 906 907 908 909 910 911 |
# File 'lib/versionomy/format/delimiter.rb', line 905 def unparsed_value(value_, style_, unparse_params_) if !@strip_leading_zeros && (width_ = unparse_params_[@width_unparse_param_key]) "%0#{width_.to_i}d" % value_ else value_.to_s end end |