Class: Valean
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(other) ⇒ Object
- #ensure(*bits) ⇒ Object
- #errors ⇒ Object
-
#initialize(name = nil, required = nil, others = {}) ⇒ Valean
constructor
Valean.new => (required, exists, valid) Valean.new(true) => (required, missing, valid) Valean.new(false) => (optional, missing, valid) Valean.new(false, :exists => true) => (optional, exists, valid).
- #perfect? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(name = nil, required = nil, others = {}) ⇒ Valean
Valean.new => (required, exists, valid) Valean.new(true) => (required, missing, valid) Valean.new(false) => (optional, missing, valid) Valean.new(false, :exists => true) => (optional, exists, valid)
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/quickbooks/xsd/validation.rb', line 25 def initialize(name=nil, required=nil, others={}) @name = name if required.nil? @required = true @exists = true else @required = required end @valid = true others.each do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
20 21 22 |
# File 'lib/quickbooks/xsd/validation.rb', line 20 def name @name end |
Class Method Details
Instance Method Details
#<<(other) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/quickbooks/xsd/validation.rb', line 39 def <<(other) puts "Importing #{other} into #{self} (#{required?}):" if $DEBUG @exists = false if other.missing? && other.required? @valid = false if other.invalid? errors.concat(other.errors.map {|i| name ? "#{name}: #{i}" : i}) puts "#{self}" if $DEBUG self end |
#ensure(*bits) ⇒ Object
52 53 54 |
# File 'lib/quickbooks/xsd/validation.rb', line 52 def ensure(*bits) bits.all? {|bit| send("#{bit}?")} end |
#errors ⇒ Object
48 49 50 |
# File 'lib/quickbooks/xsd/validation.rb', line 48 def errors @errors ||= [] end |
#perfect? ⇒ Boolean
56 57 58 59 60 61 |
# File 'lib/quickbooks/xsd/validation.rb', line 56 def perfect? v = valid? ? true : false required? ? (exists? ? v : false) : (exists? ? v : true) end |
#to_s ⇒ Object Also known as: inspect
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/quickbooks/xsd/validation.rb', line 63 def to_s re = required? ? 'required' : 'optional' ex = exists? ? 'exists' : 'missing' va = valid? ? 'valid' : 'invalid' # (invalid) - required, exists but invalid # (perfect) - required, exists and valid # (missing) - required but missing # (invalid) - optional, exists but invalid # (great) - optional, exists and valid # (fine) - optional but missing required? ? (exists? ? (valid? ? '(perfect)' : '(invalid)') : '(missing)') : (exists? ? (valid? ? '(great)' : '(invalid)') : '(fine)') # valid? ? ((required? && exists?) ? "(perfect)" : "(fine)") : (exists? ? "(#{re}, invalid)" : "(#{re}, missing)") end |