abachrome 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/abachrome/color.rb +9 -1
- data/lib/abachrome/version.rb +1 -1
- data/lib/abachrome.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51acc020e50052f3aacc9d0e847809f62d84111fad86feb8889e3dc324d17385
|
4
|
+
data.tar.gz: 8649cab609da6a1c70dd94f9e77adf01b3fee441b8586d73dbcb2822c15eb7f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b5d9b1aa20997c618adf7a337d7f85d533cb937d6d5005f4030dcb96a0b4f88a106ad9c311ecf5a7139a3b09a0ee54502133e6586a78e2983056b41cad2648
|
7
|
+
data.tar.gz: 5a9850d26a1e83b6b803de4862d5267499dfe92c752deb54abfef992c80239f83bf8af9f3095c445dcc61bc7a2bd40daa6afaaf443fd997d521789db467aca50
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.4] - 2025-10-12
|
4
|
+
|
5
|
+
- Added `Color#to_hex` method for convenient hex string output
|
6
|
+
- Added `Abachrome.parse` method for parsing CSS color strings
|
7
|
+
|
3
8
|
## [0.1.3] - 2025-10-12
|
4
9
|
|
5
10
|
- Enhanced color parsing with support for additional CSS formats
|
data/lib/abachrome/color.rb
CHANGED
@@ -134,7 +134,7 @@ module Abachrome
|
|
134
134
|
end
|
135
135
|
|
136
136
|
# Returns a string representation of the color in the format "ColorSpaceName(coord1, coord2, coord3, alpha)"
|
137
|
-
#
|
137
|
+
#
|
138
138
|
# @return [String] A human-readable string representation of the color showing its
|
139
139
|
# color space name, coordinate values rounded to 3 decimal places, and alpha value
|
140
140
|
# (if not 1.0)
|
@@ -144,6 +144,14 @@ module Abachrome
|
|
144
144
|
"#{color_space.name}(#{coord_str}#{alpha_str})"
|
145
145
|
end
|
146
146
|
|
147
|
+
# Returns the color as a hexadecimal string representation.
|
148
|
+
#
|
149
|
+
# @return [String] A hex color string in the format "#RRGGBB" or "#RRGGBBAA" if alpha < 1.0
|
150
|
+
def to_hex
|
151
|
+
require_relative "outputs/css"
|
152
|
+
Outputs::CSS.format_hex(self)
|
153
|
+
end
|
154
|
+
|
147
155
|
private
|
148
156
|
|
149
157
|
# Validates that the number of coordinates matches the expected number for the color space.
|
data/lib/abachrome/version.rb
CHANGED
data/lib/abachrome.rb
CHANGED
@@ -129,7 +129,7 @@ module Abachrome
|
|
129
129
|
end
|
130
130
|
|
131
131
|
# Creates a color object from a CSS color name.
|
132
|
-
#
|
132
|
+
#
|
133
133
|
# @param color_name [String] The CSS color name (e.g., 'red', 'blue', 'cornflowerblue').
|
134
134
|
# Case-insensitive.
|
135
135
|
# @return [Abachrome::Color, nil] A color object in the RGB color space if the name is valid,
|
@@ -141,6 +141,15 @@ module Abachrome
|
|
141
141
|
from_rgb(*rgb_values.map { |v| v / 255.0 })
|
142
142
|
end
|
143
143
|
|
144
|
+
# Parses a CSS color string and returns a Color object.
|
145
|
+
#
|
146
|
+
# @param css_string [String] The CSS color string to parse (e.g., "#ff0000", "rgb(255, 0, 0)", "red")
|
147
|
+
# @return [Abachrome::Color, nil] A Color object if parsing succeeds, nil otherwise
|
148
|
+
def parse(css_string)
|
149
|
+
require_relative "abachrome/parsers/css"
|
150
|
+
Parsers::CSS.parse(css_string)
|
151
|
+
end
|
152
|
+
|
144
153
|
# Convert a color from its current color space to another color space.
|
145
154
|
#
|
146
155
|
# @param color [Abachrome::Color] The color object to convert
|