lib/cliutils/prefs/pref.rb in cliutils-1.2.3 vs lib/cliutils/prefs/pref.rb in cliutils-1.2.4

- old
+ new

@@ -1,8 +1,8 @@ require 'cliutils/messenging' -require 'cliutils/prefs/pref-behavior' -require 'cliutils/prefs/pref-validation' +require 'cliutils/prefs/pref_behavior' +require 'cliutils/prefs/pref_validation' module CLIUtils # Pref Class # An individual preference class Pref @@ -41,11 +41,11 @@ attr_accessor :prereqs # Stores the prompt text. # @return [String] attr_accessor :prompt - + # Stores key/value combinations required to show this Pref. # @return [Hash] attr_accessor :validators # Initializes a new Pref via passed-in parameters. @@ -57,20 +57,13 @@ # Custom equality operator for this class. # @param [Pref] other # @return [Boolean] def ==(other) - return self.answer == other.answer && - self.behaviors == other.behaviors && - self.config_key == other.config_key && - self.config_section == other.config_section && - self.default == other.default && - self.last_error_message == other.last_error_message && - self.options == other.options && - self.prereqs == other.prereqs && - self.prompt == other.prompt && - self.validators == other.validators + @config_key == other.config_key && + @config_section == other.config_section && + @prompt == other.prompt end # Runs the passed text through this Pref's behaviors. # @param [String] text The text to evaluate # @return [String] @@ -82,11 +75,10 @@ modified_text = PrefBehavior.send(b, modified_text) else messenger.warn("Skipping undefined Pref behavior: #{ b }") end end - modified_text else text end end @@ -97,25 +89,25 @@ # @return [Boolean] def validate(text) _confirm_options(text) && _confirm_validators(text) end - + private # Validates a text against the options for this Pref # @param [String] text The text to validate # @return [Boolean] def _confirm_options(text) ret = true if @options unless @options.include?(text) - @last_error_message = "Invalid option chosen (\"#{ text }\"); valid options are: #{ options }" + @last_error_message = "Invalid option chosen (\"#{ text }\");"\ + "valid options are: #{ options }" ret = false end end - ret end # Validates a text against the validators for this Pref # @param [String] text The text to validate @@ -133,10 +125,9 @@ else messenger.warn("Skipping undefined Pref validator: #{ v }") end end end - ret end end -end \ No newline at end of file +end