Class: EverydayMenu::CommandList
- Inherits:
-
Object
- Object
- EverydayMenu::CommandList
- Defined in:
- lib/everyday-menu/utils.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #add(command_id = nil, &block) ⇒ Object
- #canExecute ⇒ Object
- #execute(sender) ⇒ Object
-
#initialize(parent, label) ⇒ CommandList
constructor
A new instance of CommandList.
- #md5(str) ⇒ Object
- #rand_id ⇒ Object
- #unique_id ⇒ Object
Constructor Details
#initialize(parent, label) ⇒ CommandList
Returns a new instance of CommandList.
32 33 34 35 36 37 |
# File 'lib/everyday-menu/utils.rb', line 32 def initialize(parent, label) @parent = parent @label = label @items = {} @rand = Random.new end |
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
30 31 32 |
# File 'lib/everyday-menu/utils.rb', line 30 def label @label end |
Instance Method Details
#[](id) ⇒ Object
56 57 58 |
# File 'lib/everyday-menu/utils.rb', line 56 def [](id) @items[id] end |
#add(command_id = nil, &block) ⇒ Object
51 52 53 54 |
# File 'lib/everyday-menu/utils.rb', line 51 def add(command_id = nil, &block) id = command_id || rand_id @items[id] = EverydayCommand.new(@parent, @label, id, &block) end |
#canExecute ⇒ Object
64 65 66 |
# File 'lib/everyday-menu/utils.rb', line 64 def canExecute @items.values.any? { |item| item.canExecute } end |
#execute(sender) ⇒ Object
60 61 62 |
# File 'lib/everyday-menu/utils.rb', line 60 def execute(sender) @items.values.each { |item| item.execute(sender) } end |
#md5(str) ⇒ Object
39 40 41 |
# File 'lib/everyday-menu/utils.rb', line 39 def md5(str) str.dataUsingEncoding(NSUTF8StringEncoding).MD5HexDigest end |
#rand_id ⇒ Object
47 48 49 |
# File 'lib/everyday-menu/utils.rb', line 47 def rand_id :"command_id_#{unique_id}" end |
#unique_id ⇒ Object
43 44 45 |
# File 'lib/everyday-menu/utils.rb', line 43 def unique_id md5(WeakRef.new("#{@rand.rand}#{@rand.rand}")) end |