Class: Motion::Option
- Inherits:
-
Object
- Object
- Motion::Option
- Defined in:
- lib/project/motion_option.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #add(text, style = nil, &block) ⇒ Object
- #attach_to(view) ⇒ Object
- #count ⇒ Object
- #each ⇒ Object
- #first ⇒ Object
-
#initialize ⇒ Option
constructor
A new instance of Option.
Constructor Details
#initialize ⇒ Option
Returns a new instance of Option.
5 6 7 8 |
# File 'lib/project/motion_option.rb', line 5 def initialize self.actions = [] self end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
3 4 5 |
# File 'lib/project/motion_option.rb', line 3 def actions @actions end |
Instance Method Details
#[](index) ⇒ Object
14 15 16 |
# File 'lib/project/motion_option.rb', line 14 def [](index) actions[index] end |
#add(text, style = nil, &block) ⇒ Object
10 11 12 |
# File 'lib/project/motion_option.rb', line 10 def add(text, style=nil, &block) actions << Action.new(title: text, style: style, action: block) end |
#attach_to(view) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/project/motion_option.rb', line 30 def attach_to(view) case view when UIAlertView, UIActionSheet actions.each_with_index do |action, index| view.addButtonWithTitle(action.title) case action.style when UIAlertActionStyleCancel view.cancelButtonIndex = index when UIAlertActionStyleDestructive view.destructiveButtonIndex = index end end when UIAlertController actions.each do |a| alert_action = UIAlertAction.actionWithTitle( a.title, style: a.style, handler: ->(arg) { a.action ? a.action.call : nil } ) view.addAction(alert_action) end end view end |
#count ⇒ Object
18 19 20 |
# File 'lib/project/motion_option.rb', line 18 def count actions.count end |
#each ⇒ Object
26 27 28 |
# File 'lib/project/motion_option.rb', line 26 def each actions.each end |
#first ⇒ Object
22 23 24 |
# File 'lib/project/motion_option.rb', line 22 def first actions.first end |