Class: GitTest::Notify::TextFormat
- Inherits:
-
Object
- Object
- GitTest::Notify::TextFormat
- Defined in:
- lib/git_test/notify.rb
Constant Summary collapse
- ENGINE =
"#=="
- CABOOSE =
"==#"
- FILL_CHAR =
"="
Instance Attribute Summary collapse
-
#filler ⇒ Object
Returns the value of attribute filler.
-
#length ⇒ Object
Returns the value of attribute length.
-
#msg ⇒ Object
Returns the value of attribute msg.
Instance Method Summary collapse
-
#add_filler! ⇒ Object
def truncate_message! self.msg # = msg[0, msg.length + filler_length_needed - 3 ] << “…” end.
- #even? ⇒ Boolean
- #filler_length_needed ⇒ Object
- #filler_per_side ⇒ Object
-
#initialize(msg, length) ⇒ TextFormat
constructor
A new instance of TextFormat.
- #message_too_long? ⇒ Boolean
- #normalize ⇒ Object
- #odd? ⇒ Boolean
- #output ⇒ Object
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
#filler ⇒ Object
Returns the value of attribute filler.
4 5 6 |
# File 'lib/git_test/notify.rb', line 4 def filler @filler end |
#length ⇒ Object
Returns the value of attribute length.
4 5 6 |
# File 'lib/git_test/notify.rb', line 4 def length @length end |
#msg ⇒ Object
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
26 27 28 |
# File 'lib/git_test/notify.rb', line 26 def even? filler_per_side % 2 == 0 end |
#filler_length_needed ⇒ Object
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_side ⇒ Object
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
30 31 32 |
# File 'lib/git_test/notify.rb', line 30 def filler_length_needed < 0 end |
#normalize ⇒ Object
51 52 53 54 |
# File 'lib/git_test/notify.rb', line 51 def normalize add_filler! output end |
#odd? ⇒ Boolean
22 23 24 |
# File 'lib/git_test/notify.rb', line 22 def odd? !even? end |
#output ⇒ Object
47 48 49 |
# File 'lib/git_test/notify.rb', line 47 def output "#{ENGINE}#{msg}" end |