Class: Helpr::Help
- Inherits:
-
Object
- Object
- Helpr::Help
- Defined in:
- lib/helpr.rb
Instance Attribute Summary collapse
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
- #add(name, text) ⇒ Object
- #help ⇒ Object
- #hierarchy ⇒ Object
- #topics(keys = nil) ⇒ Object
- #topics_aux(keys, hier) ⇒ Object
Instance Attribute Details
#top ⇒ Object
Returns the value of attribute top.
5 6 7 |
# File 'lib/helpr.rb', line 5 def top @top end |
Instance Method Details
#[](name) ⇒ Object
12 13 14 |
# File 'lib/helpr.rb', line 12 def [](name) help[name.to_sym] end |
#[]=(name, val) ⇒ Object
16 17 18 |
# File 'lib/helpr.rb', line 16 def []=(name, val) help[name.to_sym] = val end |
#add(name, text) ⇒ Object
7 8 9 10 |
# File 'lib/helpr.rb', line 7 def add(name, text) self[name] = text topics(name.split(' ')) end |
#help ⇒ Object
20 21 22 |
# File 'lib/helpr.rb', line 20 def help @help ||= Hash.new end |
#hierarchy ⇒ Object
49 50 51 |
# File 'lib/helpr.rb', line 49 def hierarchy @hierarchy ||= Hash.new end |
#topics(keys = nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/helpr.rb', line 24 def topics(keys=nil) result = if keys.nil? hierarchy else topics_aux(keys, hierarchy) end result.keys end |
#topics_aux(keys, hier) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/helpr.rb', line 33 def topics_aux(keys, hier) key = if keys.empty? '' else keys.shift.to_sym end hier = hier.fetch(key) do hier[key] = {} end if keys.empty? hier else topics_aux(keys, hier) end end |