Class: Unmagic::Color::Alpha
- Inherits:
-
Util::Percentage
- Object
- Util::Percentage
- Unmagic::Color::Alpha
- Defined in:
- lib/unmagic/color.rb
Overview
Alpha channel for transparency. Stored internally as percentage (0-100%) where 100% is fully opaque and 0% is fully transparent. Use to_css to output as ratio (0.0-1.0) for CSS formats.
Inherits parse method from Percentage which handles:
-
Explicit percentage: “50%” → Alpha with value 50.0
-
Fraction notation: “1/2” → Alpha with value 50.0
-
Bare decimal ≤ 1.0: “0.5” → Alpha with value 50.0 (treated as CSS ratio)
-
Bare decimal > 1.0: “75” → Alpha with value 75.0
Constant Summary collapse
- DEFAULT =
Default alpha value (fully opaque)
new(value: 100).freeze
Instance Attribute Summary
Attributes inherited from Util::Percentage
Instance Method Summary collapse
-
#to_css ⇒ String
Convert to CSS output format (as ratio 0.0-1.0, not percentage).
Methods inherited from Util::Percentage
#+, #-, #<=>, #==, #abs, build, #initialize, parse, #pretty_print, #to_f, #to_ratio, #to_s, #zero?
Constructor Details
This class inherits a constructor from Unmagic::Util::Percentage
Instance Method Details
#to_css ⇒ String
Convert to CSS output format (as ratio 0.0-1.0, not percentage).
Returns “1” for fully opaque, “0” for fully transparent, and decimal values for semi-transparent colors (e.g., “0.5”, “0.75”).
353 354 355 356 |
# File 'lib/unmagic/color.rb', line 353 def to_css ratio = to_ratio ratio == 1.0 ? "1" : ratio.to_s.sub(/\.?0+$/, "") end |