class Kiq::CLI::Project

Hosts logic for the backer object

Attributes

amount[RW]

Allows access to name, amount, and backers

backers[RW]

Allows access to name, amount, and backers

name[RW]

Allows access to name, amount, and backers

Public Class Methods

all_offspring() click to toggle source

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
check_amount_dollar_sign(amount) click to toggle source

@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
check_input_length(input) click to toggle source

@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
check_name_characters(name) click to toggle source

@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
check_name_length(name) click to toggle source

@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
new(name, amount, backers={}) click to toggle source

@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
project_does_not_exist?(project, projects) click to toggle source

@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
validate_project(project, projects) click to toggle source

@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