Class: Histock::Helper
- Inherits:
-
Object
- Object
- Histock::Helper
- Defined in:
- lib/histock/filter/helper.rb
Class Method Summary collapse
-
.currency_to_number(str) ⇒ Object
should check str by ‘is_currency?’ method before calling this method.
- .is_currency?(str) ⇒ Boolean
- .is_float?(str) ⇒ Boolean
- .is_persentage?(str) ⇒ Boolean
-
.persentage_to_number(str) ⇒ Object
should check str by ‘is_persentage?’ method before calling this method.
Class Method Details
.currency_to_number(str) ⇒ Object
should check str by ‘is_currency?’ method before calling this method
22 23 24 |
# File 'lib/histock/filter/helper.rb', line 22 def currency_to_number(str) str.to_s.gsub(/[$,]/,'').to_i end |
.is_currency?(str) ⇒ Boolean
8 9 10 |
# File 'lib/histock/filter/helper.rb', line 8 def is_currency?(str) str.match(/^[+-]?\d{1,3}(,\d{3})*$/).nil? ? false : true end |
.is_float?(str) ⇒ Boolean
12 13 14 |
# File 'lib/histock/filter/helper.rb', line 12 def is_float?(str) str.match(/^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)$/).nil? ? false : true end |
.is_persentage?(str) ⇒ Boolean
4 5 6 |
# File 'lib/histock/filter/helper.rb', line 4 def is_persentage?(str) str.match(/^[+-]?([0-9]+(\.[0-9]*)?|\.[0-9]+)%$/).nil? ? false : true end |
.persentage_to_number(str) ⇒ Object
should check str by ‘is_persentage?’ method before calling this method
17 18 19 |
# File 'lib/histock/filter/helper.rb', line 17 def persentage_to_number(str) str.to_s.gsub(/%/,'').to_f end |