Class: Vedeu::Colours::Repository
- Inherits:
-
Object
- Object
- Vedeu::Colours::Repository
- Defined in:
- lib/vedeu/colours/repository.rb
Overview
Allows the storing of HTML/CSS colours and their respective escape sequences.
Direct Known Subclasses
Instance Attribute Summary collapse
- #storage ⇒ Hash<String => String> (also: #all) readonly
Instance Method Summary collapse
-
#initialize ⇒ Vedeu::Colours::Repository
constructor
Returns a new instance of Vedeu::Colours::Repository.
-
#register(colour, escape_sequence) ⇒ String
Registers a colour with respective escape sequence.
-
#registered?(colour) ⇒ Boolean
Returns a boolean indicating whether the colour has been sregistered.
-
#reset! ⇒ Hash
Removes all stored colours.
-
#retrieve(colour) ⇒ String
Retrieves the escape sequence of a registered colour.
Constructor Details
#initialize ⇒ Vedeu::Colours::Repository
Returns a new instance of Vedeu::Colours::Repository.
20 21 22 |
# File 'lib/vedeu/colours/repository.rb', line 20 def initialize @storage = {} end |
Instance Attribute Details
#storage ⇒ Hash<String => String> (readonly) Also known as: all
14 15 16 |
# File 'lib/vedeu/colours/repository.rb', line 14 def storage @storage end |
Instance Method Details
#register(colour, escape_sequence) ⇒ String
Registers a colour with respective escape sequence.
27 28 29 |
# File 'lib/vedeu/colours/repository.rb', line 27 def register(colour, escape_sequence) storage.store(colour, escape_sequence) end |
#registered?(colour) ⇒ Boolean
Returns a boolean indicating whether the colour has been sregistered.
36 37 38 39 40 |
# File 'lib/vedeu/colours/repository.rb', line 36 def registered?(colour) return false unless colour storage.key?(colour) end |
#reset! ⇒ Hash
Removes all stored colours.
45 46 47 |
# File 'lib/vedeu/colours/repository.rb', line 45 def reset! storage.clear end |
#retrieve(colour) ⇒ String
Retrieves the escape sequence of a registered colour.
52 53 54 |
# File 'lib/vedeu/colours/repository.rb', line 52 def retrieve(colour) storage.fetch(colour, '') end |