Class: Stylish::Percentage
- Inherits:
-
Object
- Object
- Stylish::Percentage
- Defined in:
- lib/stylish/numeric.rb
Constant Summary collapse
- PCTSTR =
/-?(0\.)?\d+%/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ Percentage
constructor
A new instance of Percentage.
- #to_s(symbols = {}, scope = "") ⇒ Object
Constructor Details
#initialize(value) ⇒ Percentage
Returns a new instance of Percentage.
6 7 8 9 10 11 12 13 14 |
# File 'lib/stylish/numeric.rb', line 6 def initialize(value) value = value[0..-2] if value =~ /^\d+$/ @number = value.to_i else @number = value.to_f end end |
Class Method Details
.match?(value) ⇒ Boolean
20 21 22 |
# File 'lib/stylish/numeric.rb', line 20 def self.match?(value) value =~ /^#{PCTSTR}$/ end |
Instance Method Details
#to_s(symbols = {}, scope = "") ⇒ Object
16 17 18 |
# File 'lib/stylish/numeric.rb', line 16 def to_s(symbols = {}, scope = "") @number.to_s + "%" end |