Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/drep/alterers/drep_helpers.rb,
lib/drep/alterers/drep_validators.rb
Overview
DRep - Modular Open Software Tester.
Copyright (C) 2009 Dmitrii Toksaitov
This file is part of DRep.
DRep is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DRep is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DRep. If not, see <http://www.gnu.org/licenses/>.
Instance Method Summary collapse
- #error(message) ⇒ Object (also: #err)
- #first_valid(item, *args) ⇒ Object
- #first_valid_text(strs, *patterns) ⇒ Object (also: #first_text)
- #form_str_from_list(list, separator = ', ') ⇒ Object
- #matched?(str, pattern) ⇒ Boolean
- #message(message) ⇒ Object (also: #msg)
- #report(ios, message) ⇒ Object
- #valid(item, *args, &block) ⇒ Object
- #valid?(item, *args, &block) ⇒ Boolean
- #valid_hash_args(*args, &block) ⇒ Object
- #valid_hash_args?(*args) {|block| ... } ⇒ Boolean
- #valid_string(item, *args, &block) ⇒ Object
- #valid_string?(item, *args, &block) ⇒ Boolean
Instance Method Details
#error(message) ⇒ Object Also known as: err
31 32 33 34 35 36 37 38 39 |
# File 'lib/drep/alterers/drep_helpers.rb', line 31 def error() if defined? @env.stderr if not defined? @env..quiet or not @env..quiet report(@env.stderr, ) end else report(STDERR, ) end end |
#first_valid(item, *args) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/drep/alterers/drep_helpers.rb', line 62 def first_valid(item, *args) result = item if result.nil? and not args.nil? args.each do |obj| unless obj.nil? result = obj; break end end end return result end |
#first_valid_text(strs, *patterns) ⇒ Object Also known as: first_text
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/drep/alterers/drep_helpers.rb', line 76 def first_valid_text(strs, *patterns) result = nil if strs.is_a?(Array) strs.each do |str| if str.is_a?(String) temp_str = str if not temp_str.empty? and patterns.is_a?(Array) temp_str.remove_nl!(); temp_str.br_to_nl!() temp_str.(); temp_str.safe_strip!() result = temp_str patterns.each do |pattern| if pattern.is_a?(Regexp) and not pattern.match(result).to_s().size == result.size result = nil break end end end end break unless result.nil? end end if result.nil? result = '' else result.safe_strip!() end return result end |
#form_str_from_list(list, separator = ', ') ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/drep/alterers/drep_helpers.rb', line 49 def form_str_from_list(list, separator = ', ') result = '' if list.is_a?(Array) list.each_index do |i| result += list[i].to_s() result += (i != list.size - 1) ? separator.to_s() : '' end end return result end |
#matched?(str, pattern) ⇒ Boolean
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/drep/alterers/drep_validators.rb', line 106 def matched?(str, pattern) result = false if str.is_a?(String) and pattern.is_a?(Regexp) if pattern.match(str).to_s().size == str.size result = true end end return result end |
#message(message) ⇒ Object Also known as: msg
20 21 22 23 24 25 26 27 28 |
# File 'lib/drep/alterers/drep_helpers.rb', line 20 def () if defined? @env.stdout if not defined? @env..quiet or !@env..quiet report(@env.stdout, ) end else report(STDOUT, ) end end |
#report(ios, message) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/drep/alterers/drep_helpers.rb', line 42 def report(ios, ) if ios.is_a?(IO) and .is_a?(String) then ios.puts() end end |
#valid(item, *args, &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/drep/alterers/drep_validators.rb', line 20 def valid(item, *args, &block) if valid?(item, *args) yield block if block_given? end end |
#valid?(item, *args, &block) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/drep/alterers/drep_validators.rb', line 26 def valid?(item, *args, &block) result = item.nil? ? false : true if result and args.is_a?(Enumerable) args.each do |obj| if obj.nil? or obj.is_a?(FalseClass) result = false; break end end end if block_given? yield block if result end return result end |
#valid_hash_args(*args, &block) ⇒ Object
74 75 76 77 78 |
# File 'lib/drep/alterers/drep_validators.rb', line 74 def valid_hash_args(*args, &block) if valid_hash_args?(args) yield block if block_given? end end |
#valid_hash_args?(*args) {|block| ... } ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/drep/alterers/drep_validators.rb', line 80 def valid_hash_args?(*args, &block) result = args.is_a?(Array) ? true : false if result args.each do |property| if property.is_a?(Hash) property.each do |name, value| unless name.is_a?(Symbol) or name.is_a?(String) then result = false end end else result = false end break unless result end end yield block if result and block_given? return result end |
#valid_string(item, *args, &block) ⇒ Object
44 45 46 47 48 |
# File 'lib/drep/alterers/drep_validators.rb', line 44 def valid_string(item, *args, &block) if valid_string?(item, *args) yield block if block_given? end end |
#valid_string?(item, *args, &block) ⇒ Boolean
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/drep/alterers/drep_validators.rb', line 50 def valid_string?(item, *args, &block) if item.is_a?(String) and !item.strip().empty? result = true else result = false end if result and args.is_a?(Enumerable) args.each do |obj| if obj.nil? or !obj.is_a?(String) or obj.strip().empty? then result = false; break end end end if block_given? yield block if result end return result end |