Class: RChoice::Choice

Inherits:
Object show all
Includes:
FromHash
Defined in:
lib/rchoice/choice.rb

Direct Known Subclasses

ProcChoice

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_blkObject

Returns the value of attribute action_blk.



4
5
6
# File 'lib/rchoice/choice.rb', line 4

def action_blk
  @action_blk
end

#chooserObject

Returns the value of attribute chooser.



4
5
6
# File 'lib/rchoice/choice.rb', line 4

def chooser
  @chooser
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/rchoice/choice.rb', line 4

def name
  @name
end

#optionalObject

Returns the value of attribute optional.



4
5
6
# File 'lib/rchoice/choice.rb', line 4

def optional
  @optional
end

#parent_objObject

Returns the value of attribute parent_obj.



4
5
6
# File 'lib/rchoice/choice.rb', line 4

def parent_obj
  @parent_obj
end

Instance Method Details

#add_option(obj, &b) ⇒ Object



26
27
28
# File 'lib/rchoice/choice.rb', line 26

def add_option(obj,&b)
  self.options << make_option(obj,&b)
end

#execute!Object



17
18
19
20
# File 'lib/rchoice/choice.rb', line 17

def execute!
  return unless action_blk
  chosen_option.execute!(&action_blk) if chosen_option
end

#make_option(obj, &b) ⇒ Object



21
22
23
24
25
# File 'lib/rchoice/choice.rb', line 21

def make_option(obj,&b)
  return obj if obj.kind_of?(Option)
  obj = {:base_obj => obj} unless obj.kind_of?(Hash)
  Option.new(obj)
end

#options=(raw) ⇒ Object



29
30
31
# File 'lib/rchoice/choice.rb', line 29

def options=(raw)
  @options = raw.map { |r| make_option(r) }
end