Class: Worklog::Project
- Inherits:
-
Object
- Object
- Worklog::Project
- 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
-
#description ⇒ String?
A description of the project, can be nil.
-
#end_date ⇒ Date?
The end date of the project, can be nil.
-
#entries ⇒ Array<LogEntry>
These entries are related to the work done on this project.
-
#key ⇒ String
Unique identifier for the project, used in log entries.
-
#last_activity ⇒ Date?
The last activity is not stored in the project itself.
-
#name ⇒ String
The human-readable name of the project.
-
#repositories ⇒ Array<String>
These repositories are used for linking the Github commits to the project.
-
#start_date ⇒ Date?
The start date of the project, can be nil.
-
#status ⇒ String?
Possible values: ‘active’, ‘completed’, ‘archived’, etc.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Project
Creates a new Project instance from a hash of attributes.
Instance Method Summary collapse
-
#activity_graph ⇒ String
Generate an ASCII activity graph for the project.
-
#contains_repository?(repository) ⇒ Boolean
Returns true if the project contains the given repository URL.
-
#ended? ⇒ Boolean
Returns true if the project has ended, false otherwise.
-
#project_metadata ⇒ String
Returns a string with project metadata.
-
#started? ⇒ Boolean
Returns true if the project has started, false otherwise.
Instance Attribute Details
#description ⇒ String?
Returns 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_date ⇒ Date?
Returns 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 |
#entries ⇒ Array<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.
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 |
#key ⇒ String
Returns 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_activity ⇒ Date?
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.
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 |
#name ⇒ String
Returns 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 |
#repositories ⇒ Array<String>
These repositories are used for linking the Github commits to the project. At the moment, only Github repositories are supported.
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_date ⇒ Date?
Returns 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 |
#status ⇒ String?
Possible values: ‘active’, ‘completed’, ‘archived’, etc. Indicates the current state 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 |
Class Method Details
.from_hash(hash) ⇒ Project
Creates a new Project instance from a hash of attributes.
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_graph ⇒ String
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.
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.
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.
81 82 83 |
# File 'lib/project.rb', line 81 def ended? !end_date.nil? && end_date < Date.today end |
#project_metadata ⇒ String
Returns a string with 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.
75 76 77 |
# File 'lib/project.rb', line 75 def started? start_date.nil? || (!start_date.nil? && start_date <= Date.today) end |