Class: Chimpactions::Action
- Inherits:
-
Object
- Object
- Chimpactions::Action
- Defined in:
- lib/chimpactions/action.rb
Overview
Defines a single step to take given a set of conditions.
Instance Attribute Summary collapse
-
#action ⇒ Object
The Chimpaction::Subscriber method to execute for this action.
-
#is ⇒ Object
Returns the value of attribute is.
-
#list ⇒ Object
The Chimpactions::List object to excute the action on.
-
#value ⇒ Object
Returns the value of attribute value.
-
#whenn ⇒ Object
Returns the value of attribute whenn.
Instance Method Summary collapse
-
#cast_value(val) ⇒ String, ...
Utility for casting a String to a ‘best guess’ Type.
- #execute(subscriber) ⇒ Object
- #ini_ar(ar) ⇒ Object
-
#initialize(params) ⇒ Action
constructor
A new instance of Action.
-
#perform?(subscriber) ⇒ Boolean
Check the Object attributes against the specified logic.
Constructor Details
#initialize(params) ⇒ Action
Returns a new instance of Action.
14 15 16 17 18 19 20 21 22 |
# File 'lib/chimpactions/action.rb', line 14 def initialize(params) if params.class.name == "Hash" params.each_pair do |key,val| self.send(key.to_s.dup << "=", val) end elsif params.class.name == "Chimpaction" ini_ar(params) end end |
Instance Attribute Details
#action ⇒ Object
The Chimpaction::Subscriber method to execute for this action.
6 7 8 |
# File 'lib/chimpactions/action.rb', line 6 def action @action end |
#is ⇒ Object
Returns the value of attribute is.
10 11 12 |
# File 'lib/chimpactions/action.rb', line 10 def is @is end |
#list ⇒ Object
The Chimpactions::List object to excute the action on.
8 9 10 |
# File 'lib/chimpactions/action.rb', line 8 def list @list end |
#value ⇒ Object
Returns the value of attribute value.
11 12 13 |
# File 'lib/chimpactions/action.rb', line 11 def value @value end |
#whenn ⇒ Object
Returns the value of attribute whenn.
9 10 11 |
# File 'lib/chimpactions/action.rb', line 9 def whenn @whenn end |
Instance Method Details
#cast_value(val) ⇒ String, ...
Utility for casting a String to a ‘best guess’ Type
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chimpactions/action.rb', line 56 def cast_value(val) raise ArgumentError.new("Your value is not a String! (it's a #{val.class})") if val.class != String && val.class != TrueClass && val.class != FalseClass if (Float val rescue false) Float val elsif (Integer val rescue false) Integer val elsif val =~ /^true$/i || val == true true elsif val =~ /^false$/i || val == false false else val end end |
#execute(subscriber) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/chimpactions/action.rb', line 32 def execute(subscriber) if perform?(subscriber) puts "subscriber.#{action}(\"#{list}\")" eval "subscriber.#{action}(\"#{list}\")" end end |
#ini_ar(ar) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/chimpactions/action.rb', line 24 def ini_ar(ar) attribs = %W[action list whenn is value] attribs.each do |attrib| val = ar.send(attrib) self.send(attrib.to_s.dup << "=", val) end end |
#perform?(subscriber) ⇒ Boolean
Check the Object attributes against the specified logic.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/chimpactions/action.rb', line 41 def perform?(subscriber) # puts "#{is}" if is.eql?("=") is = '==' end # puts "#{is}" value = cast_value(self.value) value = "\"#{value}\"" if value.class.name == "String" # puts "*** CHECKING : subscriber.#{whenn} #{is} #{value}" eval "subscriber.#{whenn} #{is} #{value}" end |