Class: Foraneus::Converters::Integer
- Defined in:
- lib/foraneus/converters/integer.rb
Constant Summary collapse
- DELIMITED_REGEX =
/(\d)(?=(\d\d\d)+(?!\d))/
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Integer
constructor
A new instance of Integer.
- #parse(s) ⇒ Integer
- #raw(v) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Integer
Returns a new instance of Integer.
11 12 13 14 |
# File 'lib/foraneus/converters/integer.rb', line 11 def initialize(opts = {}) @opts = opts @delimiter = opts[:delimiter] end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
7 8 9 |
# File 'lib/foraneus/converters/integer.rb', line 7 def opts @opts end |
Instance Method Details
#parse(s) ⇒ Integer
19 20 21 22 23 24 25 |
# File 'lib/foraneus/converters/integer.rb', line 19 def parse(s) raise TypeError, "can't convert nil into Integer" if s.nil? s = s.gsub(@delimiter, '') if @delimiter Kernel.Integer(s) end |
#raw(v) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/foraneus/converters/integer.rb', line 27 def raw(v) s = v.to_s if @delimiter s.gsub!(DELIMITED_REGEX) { "#{$1}#{@delimiter}" } end s end |