Class: Grid
- Inherits:
-
Object
- Object
- Grid
- Defined in:
- lib/asciinema/grid.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #as_json ⇒ Object
- #crop(x, y, width, height) ⇒ Object
- #diff(other) ⇒ Object
-
#initialize(lines) ⇒ Grid
constructor
A new instance of Grid.
Constructor Details
#initialize(lines) ⇒ Grid
Returns a new instance of Grid.
6 7 8 9 10 |
# File 'lib/asciinema/grid.rb', line 6 def initialize(lines) @lines = lines @width = lines.first && lines.first.sum(&:size) || 0 @height = lines.size end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
4 5 6 |
# File 'lib/asciinema/grid.rb', line 4 def height @height end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
4 5 6 |
# File 'lib/asciinema/grid.rb', line 4 def lines @lines end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
4 5 6 |
# File 'lib/asciinema/grid.rb', line 4 def width @width end |
Instance Method Details
#as_json ⇒ Object
26 27 28 |
# File 'lib/asciinema/grid.rb', line 26 def as_json(*) lines.as_json end |
#crop(x, y, width, height) ⇒ Object
12 13 14 15 16 |
# File 'lib/asciinema/grid.rb', line 12 def crop(x, y, width, height) cropped_lines = lines[y...y+height].map { |line| crop_line(line, x, width) } self.class.new(cropped_lines) end |
#diff(other) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/asciinema/grid.rb', line 18 def diff(other) (0...height).each_with_object({}) do |y, diff| if other.nil? || other.lines[y] != lines[y] diff[y] = lines[y] end end end |