class Kiq::CLI::Project
Hosts logic for the backer object
Attributes
Allows access to name, amount, and backers
Allows access to name, amount, and backers
Allows access to name, amount, and backers
Public Class Methods
Sets up easy was to call all instances of an object @return instances
# File lib/kiq/project.rb, line 23 def self.all_offspring @@instance_collector end
@param amount [String] Checks if the amount includes dollar signs @return [Boolean] warning if false
# File lib/kiq/project.rb, line 51 def self.check_amount_dollar_sign(amount) if !amount.include?('$') return true else puts "ERROR: Project amount must not contain the '$' character or any other alphanumeric characters. Numbers only." return false end end
@param input [Array] full user input Checks if the array is the correct length for project input @return [Boolean] warning if false
# File lib/kiq/project.rb, line 63 def self.check_input_length(input) if input.length == 3 return true else puts "ERROR: A project must have two arguments." return false end end
@param name [String] Checks if the name has non-alphanumeric characters besides underscores and dashes @return [Boolean] warning if false
# File lib/kiq/project.rb, line 75 def self.check_name_characters(name) if name.scan(/[^\w-]/).empty? return true else puts "ERROR: Project name may only use alphanumeric characters, underscores, and dashes." return false end end
@param name [String] Checks if the string is between 4 and 20 characters @return [Boolean] warning if false
# File lib/kiq/project.rb, line 87 def self.check_name_length(name) if name.length >= 4 && name.length <= 20 return true else puts "ERROR: Project name must be between 4 and 20 characters." return false end end
@param name [String] @param amount [String] @param backers [Hash] @instance_collector [Array] Initialize a project object with name and amount
# File lib/kiq/project.rb, line 14 def initialize(name, amount, backers={}) @name = name @amount = amount @backers = backers @@instance_collector << self end
@param project [Array] the user input for project @param projects [Array] all instances of Project
Checks if project already exists @return [Boolean] warning if false
# File lib/kiq/project.rb, line 42 def self.project_does_not_exist?(project, projects) if projects[project[1]].nil? return true end end
@param project [Array] the user input for project @param projects [Array] all instances of Project
Calls all validation methods for a given project @return [Boolean]
# File lib/kiq/project.rb, line 31 def self.validate_project(project, projects) name = project[1] amount = project[2] return self.check_input_length(project) && self.project_does_not_exist?(project, projects) && self.check_amount_dollar_sign(amount) && self.check_name_characters(name) && self.check_name_length(name) end