Skip to content

Commit

Permalink
Merge pull request #59 from evanthegrayt/format-changes
Browse files Browse the repository at this point in the history
Formatting updates
  • Loading branch information
evanthegrayt authored Dec 10, 2021
2 parents 3b84208 + 8711ef3 commit ba19a88
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 38 deletions.
11 changes: 3 additions & 8 deletions lib/standup_md/cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ module Helpers
#
# @return [nil]
def print(entry)
if entry.nil?
puts "No record found for #{config.cli.date}"
return
end
return puts "No record found for #{config.cli.date}" if entry.nil?

puts header(entry)
config.file.sub_header_order.each do |header_type|
tasks = entry.public_send(header_type)
Expand Down Expand Up @@ -142,7 +140,6 @@ def new_entry(file)
# @return [Array]
def previous_entry(file)
return config.entry.previous_entry unless config.cli.auto_fill_previous

return prev_entry(prev_file.load.entries) if file.new? && prev_file

prev_entry(file.entries)
Expand All @@ -155,9 +152,7 @@ def previous_entry(file)
#
# @return [StandupMD::Entry]
def prev_entry(entries)
return [] if entries.empty?

entries.last.current
entries.empty? ? [] : entries.last.current
end

##
Expand Down
5 changes: 3 additions & 2 deletions lib/standup_md/config/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class Cli
write: true,
print: false,
auto_fill_previous: true,
preference_file:
::File.expand_path(::File.join(ENV['HOME'], '.standuprc'))
preference_file: ::File.expand_path(
::File.join(ENV['HOME'], '.standuprc')
)
}.freeze

##
Expand Down
2 changes: 0 additions & 2 deletions lib/standup_md/config/entry_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module StandupMD
class Config

##
# The configuration class for StandupMD::EntryList
class EntryList

##
# The default options.
#
Expand Down
26 changes: 11 additions & 15 deletions lib/standup_md/config/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

module StandupMD
class Config

##
# The configuration class for StandupMD::File
class File

##
# The default options.
#
Expand Down Expand Up @@ -156,11 +154,9 @@ def reset
#
# @return [Integer]
def header_depth=(depth)
if !depth.between?(1, 5)
raise 'Header depth out of bounds (1..5)'
elsif depth >= sub_header_depth
@sub_header_depth = depth + 1
end
raise 'Header depth out of bounds (1..5)' if !depth.between?(1, 5)

@sub_header_depth = depth + 1 if depth >= sub_header_depth
@header_depth = depth
end

Expand All @@ -172,11 +168,9 @@ def header_depth=(depth)
#
# @return [Integer]
def sub_header_depth=(depth)
if !depth.between?(2, 6)
raise 'Sub-header depth out of bounds (2..6)'
elsif depth <= header_depth
@header_depth = depth - 1
end
raise 'Sub-header depth out of bounds (2..6)' if !depth.between?(2, 6)

@header_depth = depth - 1 if depth <= header_depth
@sub_header_depth = depth
end

Expand All @@ -188,13 +182,15 @@ def sub_header_depth=(depth)
# @return [String]
def bullet_character=(char)
raise 'Must be "-" or "*"' unless %w[- *].include?(char)

@bullet_character = char
end

##
# Setter for directory. Must be expanded in case the user uses `~` for home.
# If the directory doesn't exist, it will be created. To reset instance
# variables after changing the directory, you'll need to call load.
# Setter for directory. Must be expanded in case the user uses `~` for
# home. If the directory doesn't exist, it will be created. To reset
# instance variables after changing the directory, you'll need to call
# load.
#
# @param [String] directory
#
Expand Down
2 changes: 1 addition & 1 deletion lib/standup_md/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def self.create
# @param [Array] notes
def initialize(date, current, previous, impediments, notes = [])
raise unless date.is_a?(Date)
@config = self.class.config

@config = self.class.config
@date = date
@current = current
@previous = previous
Expand Down
18 changes: 12 additions & 6 deletions lib/standup_md/entry_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ def self.config
#
# @return [StandupMD::EntryList]
def initialize(*entries)
entries.each { |entry| validate_entry(entry) }

@config = self.class.config
unless entries.all? { |e| e.is_a?(StandupMD::Entry) }
raise ArgumentError, 'Entry must be an instance of StandupMD::Entry'
end
@entries = entries
end

Expand All @@ -38,9 +37,8 @@ def initialize(*entries)
#
# @return [Array]
def <<(entry)
unless entry.is_a?(StandupMD::Entry)
raise ArgumentError, 'Entry must be an instance of StandupMD::Entry'
end
validate_entry(entry)

@entries << entry
end

Expand Down Expand Up @@ -145,5 +143,13 @@ def to_json
#
# +last+:: The last record in the list.
def_delegators :@entries, :each, :empty?, :size, :first, :last

private

def validate_entry(entry)
return if entry.is_a?(StandupMD::Entry)

raise ArgumentError, 'Entry must be an instance of StandupMD::Entry'
end
end
end
9 changes: 7 additions & 2 deletions lib/standup_md/file/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def determine_section_type(line) # :nodoc:

def new_entry(record) # :nodoc:
Entry.new(
Date.strptime(record['header'], StandupMD.config.file.header_date_format),
Date.strptime(
record['header'],
StandupMD.config.file.header_date_format
),
record[StandupMD.config.file.current_header],
record[StandupMD.config.file.previous_header],
record[StandupMD.config.file.impediments_header],
Expand All @@ -49,7 +52,9 @@ def new_entry(record) # :nodoc:
end

def header(date)
'#' * StandupMD.config.file.header_depth + ' ' + date.strftime(StandupMD.config.file.header_date_format)
'#' * StandupMD.config.file.header_depth +
' ' +
date.strftime(StandupMD.config.file.header_date_format)
end

def sub_header(subhead)
Expand Down
4 changes: 3 additions & 1 deletion lib/standup_md/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Version
# Patch version.
#
# @return [Integer]
PATCH = 13
PATCH = 14

##
# Version as +[MAJOR, MINOR, PATCH]+
Expand All @@ -47,4 +47,6 @@ def self.to_h
Hash[%i[major minor patch].zip(to_a)]
end
end

VERSION = StandupMD::Version.to_s
end
2 changes: 1 addition & 1 deletion standup_md.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require_relative 'lib/standup_md/version'

Gem::Specification.new do |spec|
spec.name = 'standup_md'
spec.version = StandupMD::Version.to_s
spec.version = StandupMD::VERSION
spec.authors = ['Evan Gray']
spec.email = 'evanthegrayt@vivaldi.net'
spec.license = 'MIT'
Expand Down
4 changes: 4 additions & 0 deletions test/standup_md_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def test_entry_list
assert_instance_of(StandupMD::Config::EntryList, StandupMD.config.entry_list)
end

def test_version
assert_match(/\d+\.\d+.\d+/, StandupMD::VERSION)
end

def test_configure
assert_nothing_raised do
StandupMD.configure do |s|
Expand Down

0 comments on commit ba19a88

Please sign in to comment.