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> 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.
-
#retrieve_or_register(colour, escape_sequence) ⇒ String
Retrieves the escape sequence of a registered colour, or registers the colour with its respective escape sequence.
Constructor Details
#initialize ⇒ Vedeu::Colours::Repository
Returns a new instance of Vedeu::Colours::Repository.
17 18 19 |
# File 'lib/vedeu/colours/repository.rb', line 17 def initialize @storage = {} end |
Instance Attribute Details
#storage ⇒ Hash<String => String> (readonly)
12 13 14 |
# File 'lib/vedeu/colours/repository.rb', line 12 def storage @storage end |
Instance Method Details
#register(colour, escape_sequence) ⇒ String
Registers a colour with respective escape sequence.
24 25 26 |
# File 'lib/vedeu/colours/repository.rb', line 24 def register(colour, escape_sequence) storage.store(colour, escape_sequence) end |
#registered?(colour) ⇒ Boolean
Returns a boolean indicating whether the colour has been sregistered.
33 34 35 36 37 |
# File 'lib/vedeu/colours/repository.rb', line 33 def registered?(colour) return false unless colour storage.key?(colour) end |
#reset! ⇒ Hash
Removes all stored colours.
42 43 44 |
# File 'lib/vedeu/colours/repository.rb', line 42 def reset! storage.clear end |
#retrieve(colour) ⇒ String
Retrieves the escape sequence of a registered colour.
49 50 51 |
# File 'lib/vedeu/colours/repository.rb', line 49 def retrieve(colour) storage.fetch(colour, '') end |
#retrieve_or_register(colour, escape_sequence) ⇒ String
Unused - GL 2015-09-26
Retrieves the escape sequence of a registered colour, or registers the colour with its respective escape sequence.
58 59 60 61 62 63 64 65 66 |
# File 'lib/vedeu/colours/repository.rb', line 58 def retrieve_or_register(colour, escape_sequence) if registered?(colour) retrieve(colour) else register(colour, escape_sequence) end end |