Class: Transform::Parser::Number
- Defined in:
- lib/source/redshift/transform.rb
Overview
Class Color is responsible for handling css numbers values with our without units parsing them, computing new values, and returning a final value with its intial unit reapplied.
Class Method Summary collapse
-
.compute(from, to, delta) ⇒ Object
call-seq: Parser::Number.compute(number,number,float) -> string.
-
.parse(value) ⇒ Object
call-seq: Parser::Number.parse(str or number) -> number or false Parses a number value from as either a string or number and returns an integer that will later be transformed.
-
.serve(value, unit) ⇒ Object
Returns the final value as a string at the termination of a series of transformations with its inital unit reapplied.
Class Method Details
.compute(from, to, delta) ⇒ Object
call-seq:
Parser::Number.compute(number,number,float) -> string
Computes from an current value to a newvalue based on a delta and returns a css compatible string.
243 244 245 |
# File 'lib/source/redshift/transform.rb', line 243 def self.compute(from,to,delta) Transform.compute(from,to,delta) end |
.parse(value) ⇒ Object
call-seq:
Parser::Number.parse(str or number) -> number or false
Parses a number value from as either a string or number and returns an integer that will later be transformed. Returns false if the value cannot be parsed as a number
Parser::Number.parse(20) # => 20 Parser::Number.parse(0) # => 0 Parser::Number.parse(‘220px’) # => 220
Parser::Number.parse(‘left’) # => false
258 259 260 261 262 |
# File 'lib/source/redshift/transform.rb', line 258 def self.parse(value) `value = value.__value__ || String(value)` `parsed = parseFloat(value)` `(parsed || parsed == 0) ? parsed : false` end |
.serve(value, unit) ⇒ Object
Returns the final value as a string at the termination of a series of transformations with its inital unit reapplied
Parser::Number.serve(20,‘px’) # => ‘20px’ Parser::Number.serve(40, nil) # => ‘40 The second argument (unit) exists for polymorphic calls and is not used.
270 271 272 |
# File 'lib/source/redshift/transform.rb', line 270 def self.serve(value, unit) return (unit) ? value + unit : value end |