Class: Vehicles::Color

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#hexObject (readonly)

Returns the value of attribute hex.



11
12
13
# File 'lib/vehicles/color.rb', line 11

def hex
  @hex
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/vehicles/color.rb', line 11

def name
  @name
end

#slugObject (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

#hashObject



33
34
35
# File 'lib/vehicles/color.rb', line 33

def hash
  slug.hash
end

#inspectObject



37
38
39
# File 'lib/vehicles/color.rb', line 37

def inspect
  %(#<Vehicles::Color #{slug} "#{name}" #{hex}>)
end

#to_hObject



20
21
22
# File 'lib/vehicles/color.rb', line 20

def to_h
  { slug: slug, name: name, hex: hex }
end

#to_sObject



24
25
26
# File 'lib/vehicles/color.rb', line 24

def to_s
  name
end