Class: Kiq::CLI::Project
- Inherits:
-
Object
- Object
- Kiq::CLI::Project
- Defined in:
- lib/kiq/project.rb
Overview
Hosts logic for the backer object
Constant Summary collapse
- @@instance_collector =
[]
Instance Attribute Summary collapse
-
#amount ⇒ Object
Allows access to name, amount, and backers.
-
#backers ⇒ Object
Allows access to name, amount, and backers.
-
#name ⇒ Object
Allows access to name, amount, and backers.
Class Method Summary collapse
-
.all_offspring ⇒ Object
Sets up easy was to call all instances of an object.
-
.check_amount_dollar_sign(amount) ⇒ Boolean
Checks if the amount includes dollar signs.
-
.check_input_length(input) ⇒ Boolean
Checks if the array is the correct length for project input.
-
.check_name_characters(name) ⇒ Boolean
Checks if the name has non-alphanumeric characters besides underscores and dashes.
-
.check_name_length(name) ⇒ Boolean
Checks if the string is between 4 and 20 characters.
-
.project_does_not_exist?(project, projects) ⇒ Boolean
Checks if project already exists.
-
.validate_project(project, projects) ⇒ Boolean
Calls all validation methods for a given project.
Instance Method Summary collapse
-
#initialize(name, amount, backers = {}) ⇒ Project
constructor
Initialize a project object with name and amount.
Constructor Details
#initialize(name, amount, backers = {}) ⇒ Project
Initialize a project object with name and amount
14 15 16 17 18 19 |
# File 'lib/kiq/project.rb', line 14 def initialize(name, amount, backers={}) @name = name @amount = amount @backers = backers @@instance_collector << self end |
Instance Attribute Details
#amount ⇒ Object
Allows access to name, amount, and backers
7 8 9 |
# File 'lib/kiq/project.rb', line 7 def amount @amount end |
#backers ⇒ Object
Allows access to name, amount, and backers
7 8 9 |
# File 'lib/kiq/project.rb', line 7 def backers @backers end |
#name ⇒ Object
Allows access to name, amount, and backers
7 8 9 |
# File 'lib/kiq/project.rb', line 7 def name @name end |
Class Method Details
.all_offspring ⇒ Object
Sets up easy was to call all instances of an object
23 24 25 |
# File 'lib/kiq/project.rb', line 23 def self.all_offspring @@instance_collector end |
.check_amount_dollar_sign(amount) ⇒ Boolean
Checks if the amount includes dollar signs
51 52 53 54 55 56 57 58 |
# 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 |
.check_input_length(input) ⇒ Boolean
Checks if the array is the correct length for project input
63 64 65 66 67 68 69 70 |
# 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 |
.check_name_characters(name) ⇒ Boolean
Checks if the name has non-alphanumeric characters besides underscores and dashes
75 76 77 78 79 80 81 82 |
# 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 |
.check_name_length(name) ⇒ Boolean
Checks if the string is between 4 and 20 characters
87 88 89 90 91 92 93 94 |
# 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 |
.project_does_not_exist?(project, projects) ⇒ Boolean
Checks if project already exists
42 43 44 45 46 |
# File 'lib/kiq/project.rb', line 42 def self.project_does_not_exist?(project, projects) if projects[project[1]].nil? return true end end |
.validate_project(project, projects) ⇒ Boolean
Calls all validation methods for a given project
31 32 33 34 35 36 |
# 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 |