Class: HeadMusic::Utilities::HashKey
- Inherits:
-
Object
- Object
- HeadMusic::Utilities::HashKey
- Defined in:
- lib/head_music/utilities/hash_key.rb
Overview
Util for converting an object to a consistent hash key
Instance Attribute Summary collapse
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Class Method Summary collapse
Instance Method Summary collapse
- #desymbolized_string ⇒ Object private
-
#initialize(identifier) ⇒ HashKey
constructor
A new instance of HashKey.
- #normalized_string ⇒ Object private
- #to_sym ⇒ Object
- #transliterated_string ⇒ Object private
Constructor Details
#initialize(identifier) ⇒ HashKey
Returns a new instance of HashKey.
13 14 15 |
# File 'lib/head_music/utilities/hash_key.rb', line 13 def initialize(identifier) @original = identifier end |
Instance Attribute Details
#original ⇒ Object (readonly)
Returns the value of attribute original.
11 12 13 |
# File 'lib/head_music/utilities/hash_key.rb', line 11 def original @original end |
Class Method Details
.for(identifier) ⇒ Object
6 7 8 9 |
# File 'lib/head_music/utilities/hash_key.rb', line 6 def self.for(identifier) @hash_keys ||= {} @hash_keys[identifier] ||= new(identifier).to_sym end |
Instance Method Details
#desymbolized_string ⇒ Object (private)
32 33 34 35 36 37 38 39 40 |
# File 'lib/head_music/utilities/hash_key.rb', line 32 def desymbolized_string original.to_s .gsub("𝄫", "_double_flat") .gsub("♭", "_flat") .gsub("♮", "_natural") .gsub("♯", "_sharp") .gsub("#", "_sharp") .gsub("𝄪", "_double_sharp") end |
#normalized_string ⇒ Object (private)
23 24 25 26 |
# File 'lib/head_music/utilities/hash_key.rb', line 23 def normalized_string @normalized_string ||= transliterated_string.downcase.gsub(/\W+/, "_") end |
#to_sym ⇒ Object
17 18 19 |
# File 'lib/head_music/utilities/hash_key.rb', line 17 def to_sym normalized_string.to_sym end |
#transliterated_string ⇒ Object (private)
28 29 30 |
# File 'lib/head_music/utilities/hash_key.rb', line 28 def transliterated_string I18n.transliterate(desymbolized_string) end |