Class: LMDocstache::Condition
- Inherits:
-
Object
- Object
- LMDocstache::Condition
- Defined in:
- lib/lm_docstache/condition.rb
Constant Summary collapse
- InvalidOperator =
Class.new(StandardError)
- ALLOWED_OPERATORS =
%w(== ~=).freeze
- STARTING_QUOTES =
%w(' " “)
- ENDING_QUOTES =
%w(' " ”)
Instance Attribute Summary collapse
-
#left_term ⇒ Object
readonly
Returns the value of attribute left_term.
-
#negation ⇒ Object
readonly
Returns the value of attribute negation.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#original_match ⇒ Object
readonly
Returns the value of attribute original_match.
-
#right_term ⇒ Object
readonly
Returns the value of attribute right_term.
Instance Method Summary collapse
-
#initialize(left_term:, right_term:, operator:, negation: false, original_match: nil) ⇒ Condition
constructor
A new instance of Condition.
- #truthy?(value) ⇒ Boolean
Constructor Details
#initialize(left_term:, right_term:, operator:, negation: false, original_match: nil) ⇒ Condition
Returns a new instance of Condition.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lm_docstache/condition.rb', line 11 def initialize(left_term:, right_term:, operator:, negation: false, original_match: nil) @left_term = left_term @right_term = remove_quotes(right_term) @operator = operator @negation = negation @original_match = original_match unless ALLOWED_OPERATORS.include?(operator) raise InvalidOperator, "Operator '#{operator}' is invalid" end end |
Instance Attribute Details
#left_term ⇒ Object (readonly)
Returns the value of attribute left_term.
9 10 11 |
# File 'lib/lm_docstache/condition.rb', line 9 def left_term @left_term end |
#negation ⇒ Object (readonly)
Returns the value of attribute negation.
9 10 11 |
# File 'lib/lm_docstache/condition.rb', line 9 def negation @negation end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
9 10 11 |
# File 'lib/lm_docstache/condition.rb', line 9 def operator @operator end |
#original_match ⇒ Object (readonly)
Returns the value of attribute original_match.
9 10 11 |
# File 'lib/lm_docstache/condition.rb', line 9 def original_match @original_match end |
#right_term ⇒ Object (readonly)
Returns the value of attribute right_term.
9 10 11 |
# File 'lib/lm_docstache/condition.rb', line 9 def right_term @right_term end |
Instance Method Details
#truthy?(value) ⇒ Boolean
23 24 25 26 |
# File 'lib/lm_docstache/condition.rb', line 23 def truthy?(value) result = value.to_s.send(operator, right_term) negation ? !result : result end |