Class: Kiq::CLI::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/kiq/project.rb

Overview

Hosts logic for the backer object

Constant Summary collapse

@@instance_collector =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, amount, backers = {}) ⇒ Project

Initialize a project object with name and amount

Parameters:

  • name (String)
  • amount (String)
  • backers (Hash) (defaults to: {})


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

#amountObject

Allows access to name, amount, and backers



7
8
9
# File 'lib/kiq/project.rb', line 7

def amount
  @amount
end

#backersObject

Allows access to name, amount, and backers



7
8
9
# File 'lib/kiq/project.rb', line 7

def backers
  @backers
end

#nameObject

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_offspringObject

Sets up easy was to call all instances of an object

Returns:

  • instances



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

Parameters:

  • amount (String)

Returns:

  • (Boolean)

    warning if false



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

Parameters:

  • input (Array)

    full user input

Returns:

  • (Boolean)

    warning if false



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

Parameters:

  • name (String)

Returns:

  • (Boolean)

    warning if false



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

Parameters:

  • name (String)

Returns:

  • (Boolean)

    warning if false



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

Parameters:

  • project (Array)

    the user input for project

  • projects (Array)

    all instances of Project

Returns:

  • (Boolean)

    warning if false



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

Parameters:

  • project (Array)

    the user input for project

  • projects (Array)

    all instances of Project

Returns:

  • (Boolean)


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