Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyObtiva committed Aug 21, 2020
1 parent 4516103 commit c46b02a
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions lib/puts_debuggerer.rb
Expand Up @@ -91,20 +91,6 @@ def source_line_count=(value)
# => "1"
attr_reader :header

def header=(value)
if value.equal?(true)
@header = HEADER_DEFAULT
elsif value == ''
@header = nil
else
@header = value
end
end

def header?
!!@header
end

# Wrapper to include at the top and bottom of every print out (both header and footer).
# * Default value is `nil`
# * Value `true` enables wrapper as `'*'*80`
Expand All @@ -124,20 +110,6 @@ def header?
# ********************************************************************************
attr_reader :wrapper

def wrapper=(value)
if value.equal?(true)
@wrapper = WRAPPER_DEFAULT
elsif value == ''
@wrapper = nil
else
@wrapper = value
end
end

def wrapper?
!!@wrapper
end

# Footer to include at the bottom of every print out.
# * Default value is `nil`
# * Value `true` enables footer as `'*'*80`
Expand All @@ -156,19 +128,21 @@ def wrapper?
# => "1"
# ********************************************************************************
attr_reader :footer

def footer=(value)
if value.equal?(true)
@footer = FOOTER_DEFAULT
elsif value == ''
@footer = nil
else
@footer = value

['header', 'footer', 'wrapper'].each do |boundary_option|
define_method("#{boundary_option}=") do |value|
if value.equal?(true)
instance_variable_set(:"@#{boundary_option}", const_get(:"#{boundary_option.upcase}_DEFAULT"))
elsif value == ''
instance_variable_set(:"@#{boundary_option}", nil)
else
instance_variable_set(:"@#{boundary_option}", value)
end
end

define_method("#{boundary_option}?") do
!!instance_variable_get(:"@#{boundary_option}")
end
end

def footer?
!!@footer
end

# Printer is a global method symbol or lambda expression to use in printing to the user.
Expand Down

0 comments on commit c46b02a

Please sign in to comment.