Class: WTFChord::Rules
- Inherits:
-
Object
- Object
- WTFChord::Rules
- Defined in:
- lib/wtf_chord/rules.rb
Instance Attribute Summary collapse
-
#chords ⇒ Object
readonly
Returns the value of attribute chords.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
- #find(name = nil) ⇒ Object (also: #[])
-
#initialize(path) ⇒ Rules
constructor
A new instance of Rules.
Constructor Details
#initialize(path) ⇒ Rules
Returns a new instance of Rules.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wtf_chord/rules.rb', line 8 def initialize(path) @path = path rules = YAML.load_file(@path) @chords = rules[:chords] @extra = rules[:extra] @pattern = / (?<name>#{Regexp.union(@chords.keys.sort_by(&:length).reverse!)})? (?<ext>#{Regexp.union(@extra.keys.sort_by(&:length).reverse!)})? /x end |
Instance Attribute Details
#chords ⇒ Object (readonly)
Returns the value of attribute chords.
6 7 8 |
# File 'lib/wtf_chord/rules.rb', line 6 def chords @chords end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
6 7 8 |
# File 'lib/wtf_chord/rules.rb', line 6 def extra @extra end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/wtf_chord/rules.rb', line 6 def path @path end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/wtf_chord/rules.rb', line 6 def pattern @pattern end |
Instance Method Details
#find(name = nil) ⇒ Object Also known as: []
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/wtf_chord/rules.rb', line 19 def find(name = nil) steps = [] name ||= "" name.match(pattern) do |m| base = chords[m[:name]] || chords["M"] steps.concat(base) ext = extra[m[:ext]] if m[:ext] steps.concat(ext) if ext end steps.tap(&:uniq!) end |