Class: Worklog::Project

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

Overview

Represents a project. A project is a longer running task or initiative. Single log entries can be associated with a project.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionString?

Returns A description of the project, can be nil.

Returns:

  • (String, nil)

    A description of the project, can be nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#end_dateDate?

Returns The end date of the project, can be nil.

Returns:

  • (Date, nil)

    The end date of the project, can be nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#entriesArray<LogEntry>

These entries are related to the work done on this project. Entries are populated dynamically when processing daily logs. They are not stored in the project itself.

Returns:

  • (Array<LogEntry>)

    An array of log entries associated with the project.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#keyString

Returns Unique identifier for the project, used in log entries.

Returns:

  • (String)

    Unique identifier for the project, used in log entries.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#last_activityDate?

The last activity is not stored in the project itself. Instead, it is updated dynamically when processing daily logs. It represents the most recent log entry time for this project.

Returns:

  • (Date, nil)

    The last activity date or nil if not set.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#nameString

Returns The human-readable name of the project.

Returns:

  • (String)

    The human-readable name of the project.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#repositoriesArray<String>

These repositories are used for linking the Github commits to the project. At the moment, only Github repositories are supported.

Returns:

  • (Array<String>)

    An array of repository URLs associated with the project.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#start_dateDate?

Returns The start date of the project, can be nil.

Returns:

  • (Date, nil)

    The start date of the project, can be nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

#statusString?

Possible values: ‘active’, ‘completed’, ‘archived’, etc. Indicates the current state of the project.

Returns:

  • (String, nil)

    The status of the project, can be nil



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/project.rb', line 36

class Project
  attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity

  # Creates a new Project instance from a hash of attributes.
  # @param hash [Hash] A hash containing project attributes
  # @option hash [String] :key The project key
  # @option hash [String] :name The project name
  # @option hash [String] :description The project description
  # @option hash [Date] :start_date The project start date
  # @option hash [Date] :end_date The project end date
  # @option hash [String] :status The project status
  # @return [Project] A new Project instance
  def self.from_hash(hash)
    project = new

    # Protect against nil hash
    raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

    # Ensure that at least the key is present
    raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

    hash.each do |key, value|
      instance_var = "@#{key}"
      project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
    end
    # Set default values for repositories if not provided
    project.repositories ||= []
    project.repositories.map! do |repo|
      Github::Repository.from_url(repo)
    end

    project
  end

  # Returns true if the project has started, false otherwise.
  # A project is considered started if either
  #  - its start date is nil or
  #  - its start date is less than or equal to today's date.
  # @return [Boolean] true if the project has started, false otherwise
  def started?
    start_date.nil? || (!start_date.nil? && start_date <= Date.today)
  end

  # Returns true if the project has ended, false otherwise.
  # @return [Boolean] true if the project has ended, false otherwise
  def ended?
    !end_date.nil? && end_date < Date.today
  end

  # Returns true if the project contains the given repository URL.
  # @param repository [Worklog::Github::Repository] The repository to check
  # @return [Boolean] true if the project contains the repository URL, false otherwise
  def contains_repository?(repository)
    repositories.include? repository
  end

  # Returns a string with project metadata.
  # @return [String] A string containing project metadata.
  def 
    m = String.new
    m << "#{Rainbow(name).gold} (#{key})\n"
    m << "  Description: #{description}\n" if description
    m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
    m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
    m << "  Status: #{status}\n" if status
    m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
    m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
    m << "  #{activity_graph}"
    m
  end

  # Generate an ASCII activity graph for the project.
  # The graph shows activity over time, with each character representing a day.
  # More active days are represented with a different character.
  # @return [String] An ASCII representation of the activity graph.
  def activity_graph
    graph = String.new
    # Generate the graph for the last 30 days
    (0..29).each do |i|
      date = Date.today - i
      graph << if entries.any? { |entry| entry.time.to_date == date }
                 '#'
               else
                 '.'
               end
    end

    graph.reverse!

    graph << "\n"
    graph << "#{' ' * 31}^\n"
    graph << "#{' ' * 31}Today"
  end
end

Class Method Details

.from_hash(hash) ⇒ Project

Creates a new Project instance from a hash of attributes.

Parameters:

  • hash (Hash)

    A hash containing project attributes

Options Hash (hash):

  • :key (String)

    The project key

  • :name (String)

    The project name

  • :description (String)

    The project description

  • :start_date (Date)

    The project start date

  • :end_date (Date)

    The project end date

  • :status (String)

    The project status

Returns:

  • (Project)

    A new Project instance

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/project.rb', line 48

def self.from_hash(hash)
  project = new

  # Protect against nil hash
  raise ArgumentError, 'Project hash cannot be nil' if hash.nil?

  # Ensure that at least the key is present
  raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']

  hash.each do |key, value|
    instance_var = "@#{key}"
    project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
  end
  # Set default values for repositories if not provided
  project.repositories ||= []
  project.repositories.map! do |repo|
    Github::Repository.from_url(repo)
  end

  project
end

Instance Method Details

#activity_graphString

Generate an ASCII activity graph for the project. The graph shows activity over time, with each character representing a day. More active days are represented with a different character.

Returns:

  • (String)

    An ASCII representation of the activity graph.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/project.rb', line 111

def activity_graph
  graph = String.new
  # Generate the graph for the last 30 days
  (0..29).each do |i|
    date = Date.today - i
    graph << if entries.any? { |entry| entry.time.to_date == date }
               '#'
             else
               '.'
             end
  end

  graph.reverse!

  graph << "\n"
  graph << "#{' ' * 31}^\n"
  graph << "#{' ' * 31}Today"
end

#contains_repository?(repository) ⇒ Boolean

Returns true if the project contains the given repository URL.

Parameters:

Returns:

  • (Boolean)

    true if the project contains the repository URL, false otherwise



88
89
90
# File 'lib/project.rb', line 88

def contains_repository?(repository)
  repositories.include? repository
end

#ended?Boolean

Returns true if the project has ended, false otherwise.

Returns:

  • (Boolean)

    true if the project has ended, false otherwise



81
82
83
# File 'lib/project.rb', line 81

def ended?
  !end_date.nil? && end_date < Date.today
end

#project_metadataString

Returns a string with project metadata.

Returns:

  • (String)

    A string containing project metadata.



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/project.rb', line 94

def 
  m = String.new
  m << "#{Rainbow(name).gold} (#{key})\n"
  m << "  Description: #{description}\n" if description
  m << "  Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
  m << "  End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
  m << "  Status: #{status}\n" if status
  m << "  Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
  m << "  Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
  m << "  #{activity_graph}"
  m
end

#started?Boolean

Returns true if the project has started, false otherwise. A project is considered started if either

- its start date is nil or
- its start date is less than or equal to today's date.

Returns:

  • (Boolean)

    true if the project has started, false otherwise



75
76
77
# File 'lib/project.rb', line 75

def started?
  start_date.nil? || (!start_date.nil? && start_date <= Date.today)
end