Class: Card
- Inherits:
-
Object
- Object
- Card
- Defined in:
- lib/card.rb
Instance Attribute Summary collapse
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
Instance Method Summary collapse
- #init_from ⇒ Object
- #init_note ⇒ Object
- #init_sub_title ⇒ Object
- #init_title ⇒ Object
-
#initialize(title:, sub_title:, note:, from:) ⇒ Card
constructor
A new instance of Card.
- #show ⇒ Object
Constructor Details
#initialize(title:, sub_title:, note:, from:) ⇒ Card
Returns a new instance of Card.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/card.rb', line 8 def initialize(title:, sub_title:, note:, from:) @title = title @sub_title = sub_title @note = note @from = from @canvas = Canvas.new(height: 10, width: 62, frame_style:'dotted') if @title.length < 60 cjk_in_title = CJKHelper.get_cjk(@title) @title_x_start = (60 - @title.length - cjk_in_title.length)/2 else raise "title too long" end if @sub_title.length < 60 cjk_in_sub_title = CJKHelper.get_cjk(@sub_title) @sub_title_x_start = (60 - @sub_title.length - cjk_in_sub_title.length)/2 else raise "sub title too long" end init_title init_sub_title init_note init_from end |
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
6 7 8 |
# File 'lib/card.rb', line 6 def canvas @canvas end |
Instance Method Details
#init_from ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/card.rb', line 79 def init_from y = 10 - 2 x = 60 - @from.length @from.chars.each do |c| while @canvas.occupied?(x: x, y: y) x += 1 if x < 60 end @canvas.draw(y: y, x: x, symbol: c) x += 1 end end |
#init_note ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/card.rb', line 61 def init_note return if !@note y = 4 x = 2 @note.chars.each do |c| if x <= 60 while @canvas.occupied?(y:y, x:x) x += 1 if x < 60 end @canvas.draw(y: y, x: x, symbol: c) else y += 1 x = 1 end x += 1 end end |
#init_sub_title ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/card.rb', line 48 def init_sub_title y = 2 x = @sub_title_x_start @sub_title.chars.each do |c| while @canvas.occupied?(x: x, y: y) x += 1 if x < 60 end @canvas.draw(y: y, x: x, symbol: c) x += 1 end end |
#init_title ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/card.rb', line 36 def init_title y = 1 x = @title_x_start @title.chars.each do |c| while @canvas.occupied?(x: x, y: y) x += 1 if x < 60 end @canvas.draw(y: y, x: x, symbol: c) x += 1 end end |
#show ⇒ Object
92 93 94 |
# File 'lib/card.rb', line 92 def show @canvas.show end |