Class: AsciiPaint::BlockString
- Inherits:
-
Object
- Object
- AsciiPaint::BlockString
- Defined in:
- lib/ascii_paint/block_string.rb
Instance Attribute Summary collapse
-
#block_characters ⇒ Object
readonly
Returns the value of attribute block_characters.
Instance Method Summary collapse
- #each_row ⇒ Object
-
#initialize(string) ⇒ BlockString
constructor
A new instance of BlockString.
- #to_a ⇒ Object
Constructor Details
#initialize(string) ⇒ BlockString
Returns a new instance of BlockString.
5 6 7 |
# File 'lib/ascii_paint/block_string.rb', line 5 def initialize(string) @block_characters = string.chars.map { |char| BlockCharacter.new(char) } end |
Instance Attribute Details
#block_characters ⇒ Object (readonly)
Returns the value of attribute block_characters.
3 4 5 |
# File 'lib/ascii_paint/block_string.rb', line 3 def block_characters @block_characters end |
Instance Method Details
#each_row ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ascii_paint/block_string.rb', line 9 def each_row return to_enum(:each_row) unless block_given? rows = block_characters.chunk do |block_char| if block_char.newline? nil else :not_newline end end.map do |symbol, row| row end rows.each do |row| yield row end end |
#to_a ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/ascii_paint/block_string.rb', line 28 def to_a each_row.flat_map do |block_row| (0...BlockCharacter.height).map do |h| block_row.inject('') do |string_row, block_char| string_row + block_char.ascii[h] end end end end |