Class: GitTest::Notify::TextFormat

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

Constant Summary collapse

ENGINE =
"#=="
CABOOSE =
"==#"
FILL_CHAR =
"="

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg, length) ⇒ TextFormat

Returns a new instance of TextFormat.



9
10
11
12
# File 'lib/git_test/notify.rb', line 9

def initialize(msg, length)
  self.msg    = " #{msg} "
  self.length = length
end

Instance Attribute Details

#fillerObject

Returns the value of attribute filler.



4
5
6
# File 'lib/git_test/notify.rb', line 4

def filler
  @filler
end

#lengthObject

Returns the value of attribute length.



4
5
6
# File 'lib/git_test/notify.rb', line 4

def length
  @length
end

#msgObject

Returns the value of attribute msg.



4
5
6
# File 'lib/git_test/notify.rb', line 4

def msg
  @msg
end

Instance Method Details

#add_filler!Object

def truncate_message!

self.msg # = msg[0, msg.length + filler_length_needed - 3 ] << "..."

end



38
39
40
41
42
43
44
45
# File 'lib/git_test/notify.rb', line 38

def add_filler!
  filler = filler_per_side.floor.times.map {FILL_CHAR}.join("")
  # result = if even?
  #         self.msg = "#{filler}#{msg}#{filler}"
  #       else
  #         self.msg = "#{filler}#{msg}#{filler}#{FILL_CHAR}"
  #       end
end

#even?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/git_test/notify.rb', line 26

def even?
  filler_per_side % 2 == 0
end

#filler_length_neededObject



14
15
16
# File 'lib/git_test/notify.rb', line 14

def filler_length_needed
  length - (ENGINE.length + CABOOSE.length + msg.length)
end

#filler_per_sideObject



18
19
20
# File 'lib/git_test/notify.rb', line 18

def filler_per_side
  filler_length_needed/2.0
end

#message_too_long?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/git_test/notify.rb', line 30

def message_too_long?
  filler_length_needed < 0
end

#normalizeObject



51
52
53
54
# File 'lib/git_test/notify.rb', line 51

def normalize
  add_filler!
  output
end

#odd?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/git_test/notify.rb', line 22

def odd?
  !even?
end

#outputObject



47
48
49
# File 'lib/git_test/notify.rb', line 47

def output
  "#{ENGINE}#{msg}"
end