Class: Bliss::Constraint
- Inherits:
-
Object
- Object
- Bliss::Constraint
- Defined in:
- lib/bliss/constraint.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#possible_values ⇒ Object
Returns the value of attribute possible_values.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #detail ⇒ Object
- #ended! ⇒ Object
-
#initialize(depth, setting, params = {}) ⇒ Constraint
constructor
A new instance of Constraint.
-
#run!(hash = nil) ⇒ Object
TODO should exist another method passed! for tag_name_required ?.
- #tag_names ⇒ Object
Constructor Details
#initialize(depth, setting, params = {}) ⇒ Constraint
Returns a new instance of Constraint.
6 7 8 9 10 11 12 |
# File 'lib/bliss/constraint.rb', line 6 def initialize(depth, setting, params={}) @depth = depth @setting = setting @possible_values = params[:possible_values].collect(&:to_s) if params.has_key?(:possible_values) @state = :not_checked end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
3 4 5 |
# File 'lib/bliss/constraint.rb', line 3 def depth @depth end |
#possible_values ⇒ Object
Returns the value of attribute possible_values.
3 4 5 |
# File 'lib/bliss/constraint.rb', line 3 def possible_values @possible_values end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
4 5 6 |
# File 'lib/bliss/constraint.rb', line 4 def setting @setting end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/bliss/constraint.rb', line 4 def state @state end |
Instance Method Details
#detail ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/bliss/constraint.rb', line 84 def detail self.ended! # TODO esto es una chota de codigo groncho! case @state when :not_passed case @setting when :tag_name_required [@depth, "missing"] #when :not_blank # [@field.join(" or "), "blank"] #when :possible_values # [@field.join(" or "), "invalid"] end when :passed case @setting when :tag_name_required [@depth, "exists"] end end end |
#ended! ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/bliss/constraint.rb', line 75 def ended! case @setting when :tag_name_required if @state == :not_checked @state = :not_passed end end end |
#run!(hash = nil) ⇒ Object
TODO should exist another method passed! for tag_name_required ?
19 20 21 22 23 24 25 26 27 28 29 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bliss/constraint.rb', line 19 def run!(hash=nil) @state = :not_checked #@field.each do |field| #if @state == :passed # break #end case @setting when :tag_name_required content = nil if hash #puts "#{@depth.inspect} - required: #{required.inspect}" found = false self.tag_names.each do |key| if hash.keys.include?(key) found = true break end end if found @state = :passed else @state = :not_passed end else @state = :passed end when :content_values if hash found = false self.tag_names.each do |key| content = hash[key] puts content puts @possible_values.inspect if @possible_values.include?(content) found = true break end end if found @state = :passed else @state = :not_passed end end #when :not_blank # if hash.has_key?(field) and !hash[field].to_s.empty? # @state = :passed # else # @state = :not_passed # end end #end @state end |
#tag_names ⇒ Object
14 15 16 |
# File 'lib/bliss/constraint.rb', line 14 def tag_names @depth.split('/').last.gsub('(', '').gsub(')', '').split('|') end |