Class: Predicated::Operation
- Includes:
- JsonStructToJsonStr
- Defined in:
- lib/predicated/to/xml.rb,
lib/predicated/to/arel.rb,
lib/predicated/to/json.rb,
lib/predicated/evaluate.rb,
lib/predicated/predicate.rb,
lib/predicated/to/sentence.rb,
lib/predicated/simple_templated_predicate.rb,
lib/predicated/simple_templated_predicate.rb
Direct Known Subclasses
Call, Equal, GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo
Instance Attribute Summary collapse
-
#method_sym ⇒ Object
readonly
Returns the value of attribute method_sym.
Attributes inherited from Binary
Class Method Summary collapse
- .register_verb_phrase(method_sym, positive_verb_phrase, negative_verb_phrase, accepts_object = true) ⇒ Object
- .reset_verb_phrases ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #evaluate ⇒ Object
- #fill_in(placeholder_replacement) ⇒ Object
-
#initialize(left, method_sym, right) ⇒ Operation
constructor
A new instance of Operation.
- #to_arel(arel_table) ⇒ Object
- #to_json_struct ⇒ Object
- #to_negative_sentence ⇒ Object
- #to_s ⇒ Object
- #to_sentence ⇒ Object
- #to_xml(indent = "") ⇒ Object
Methods included from JsonStructToJsonStr
Methods included from Binary::FlipThroughMe
Methods included from PrintSupport
Methods inherited from Predicate
from_callable_object, from_json_str, from_json_struct, from_ruby_code_string, from_url_part, from_xml
Constructor Details
#initialize(left, method_sym, right) ⇒ Operation
Returns a new instance of Operation.
9 10 11 12 |
# File 'lib/predicated/evaluate.rb', line 9 def initialize(left, method_sym, right) super(left, right) @method_sym = method_sym end |
Instance Attribute Details
#method_sym ⇒ Object (readonly)
Returns the value of attribute method_sym.
7 8 9 |
# File 'lib/predicated/evaluate.rb', line 7 def method_sym @method_sym end |
Class Method Details
.register_verb_phrase(method_sym, positive_verb_phrase, negative_verb_phrase, accepts_object = true) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/predicated/to/sentence.rb', line 31 def self.register_verb_phrase(method_sym, positive_verb_phrase, negative_verb_phrase, accepts_object=true) @@method_sym_to_phrase_info[method_sym] = { :positive => positive_verb_phrase, :negative => negative_verb_phrase, :accepts_object => accepts_object } end |
.reset_verb_phrases ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/predicated/to/sentence.rb', line 42 def self.reset_verb_phrases @@method_sym_to_phrase_info = {} register_verb_phrase(:==, "is equal to", "is not equal to") register_verb_phrase(:>, "is greater than", "is not greater than") register_verb_phrase(:<, "is less than", "is not less than") register_verb_phrase(:>=, "is greater than or equal to", "is not greater than or equal to") register_verb_phrase(:<=, "is less than or equal to", "is not less than or equal to") register_verb_phrase(:include?, "includes", "does not include") register_verb_phrase(:is_a?, "is a", "is not a") register_verb_phrase(:nil?, "is nil", "is not nil", accepts_object=false) nil end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 |
# File 'lib/predicated/evaluate.rb', line 19 def ==(other) super && method_sym==other.method_sym end |
#evaluate ⇒ Object
14 15 16 17 |
# File 'lib/predicated/evaluate.rb', line 14 def evaluate right_values = right.nil? ? [nil] : right #1.9 problem where nils and varargs don't play nicely left.send(@method_sym, *right_values) end |
#fill_in(placeholder_replacement) ⇒ Object
33 34 35 |
# File 'lib/predicated/simple_templated_predicate.rb', line 33 def fill_in(placeholder_replacement) self.class.new(placeholder_replacement, right) end |
#to_arel(arel_table) ⇒ Object
29 30 31 |
# File 'lib/predicated/to/arel.rb', line 29 def to_arel(arel_table) arel_class.new(arel_table.attributes[left], right) end |
#to_json_struct ⇒ Object
36 37 38 |
# File 'lib/predicated/to/json.rb', line 36 def to_json_struct [left, json_sign, right] end |
#to_negative_sentence ⇒ Object
65 66 67 |
# File 'lib/predicated/to/sentence.rb', line 65 def to_negative_sentence sentence(verb_phrase[:negative]) end |
#to_s ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/predicated/simple_templated_predicate.rb', line 59 def to_s if left == Placeholder "#{self.class.shorthand}(#{part_to_s(right)})" else super end end |
#to_sentence ⇒ Object
61 62 63 |
# File 'lib/predicated/to/sentence.rb', line 61 def to_sentence sentence(verb_phrase[:positive]) end |
#to_xml(indent = "") ⇒ Object
34 35 36 |
# File 'lib/predicated/to/xml.rb', line 34 def to_xml(indent="") "#{indent}<#{tag_name}><left>#{escape(left)}</left><right>#{escape(right)}</right></#{tag_name}>" end |