Class: Vehicles::Color
- Inherits:
-
Object
- Object
- Vehicles::Color
- Defined in:
- lib/vehicles/color.rb
Overview
A canonical vehicle color. Reference data, not RDW-derived: a small, stable palette every consumer (and, in time, the hosted VehiclesDB image API) can share, so “red” means the same thing — and maps to the same image variant —everywhere. Display names are English; localize in your app (the slug is the stable, locale-independent key you store). ‘hex` is a representative swatch for UI chips / future color-accurate imagery.
Instance Attribute Summary collapse
-
#hex ⇒ Object
readonly
Returns the value of attribute hex.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(slug, name, hex) ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(slug, name, hex) ⇒ Color
Returns a new instance of Color.
13 14 15 16 17 18 |
# File 'lib/vehicles/color.rb', line 13 def initialize(slug, name, hex) @slug = slug @name = name @hex = hex freeze end |
Instance Attribute Details
#hex ⇒ Object (readonly)
Returns the value of attribute hex.
11 12 13 |
# File 'lib/vehicles/color.rb', line 11 def hex @hex end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/vehicles/color.rb', line 11 def name @name end |
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
11 12 13 |
# File 'lib/vehicles/color.rb', line 11 def slug @slug end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
28 29 30 |
# File 'lib/vehicles/color.rb', line 28 def ==(other) other.is_a?(Color) && other.slug == slug end |
#hash ⇒ Object
33 34 35 |
# File 'lib/vehicles/color.rb', line 33 def hash slug.hash end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/vehicles/color.rb', line 37 def inspect %(#<Vehicles::Color #{slug} "#{name}" #{hex}>) end |
#to_h ⇒ Object
20 21 22 |
# File 'lib/vehicles/color.rb', line 20 def to_h { slug: slug, name: name, hex: hex } end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/vehicles/color.rb', line 24 def to_s name end |