Class: Klear::Frames

Inherits:
Object
  • Object
show all
Defined in:
lib/klear/frames.rb

Defined Under Namespace

Classes: Data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns, rows, binary_string = nil) ⇒ Frames

Returns a new instance of Frames.



10
11
12
13
14
15
# File 'lib/klear/frames.rb', line 10

def initialize columns, rows, binary_string = nil
  @rows, @columns = rows, columns
  @framesize =  @rows * @columns
  @data = nil
  load(binary_string) unless binary_string.nil?
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



8
9
10
# File 'lib/klear/frames.rb', line 8

def columns
  @columns
end

#framesizeObject (readonly)

Returns the value of attribute framesize.



8
9
10
# File 'lib/klear/frames.rb', line 8

def framesize
  @framesize
end

#rowsObject (readonly)

Returns the value of attribute rows.



8
9
10
# File 'lib/klear/frames.rb', line 8

def rows
  @rows
end

Instance Method Details

#allObject



40
41
42
# File 'lib/klear/frames.rb', line 40

def all
  (0...count).map { |frame_no| get(frame_no) }
end

#countObject



22
23
24
# File 'lib/klear/frames.rb', line 22

def count
  @data.size / framesize
end

#each(&blk) ⇒ Object



26
27
28
29
30
# File 'lib/klear/frames.rb', line 26

def each &blk
  0.upto(count-1) do |frame_no|
    yield(get(frame_no), frame_no)
  end
end

#get(frame_no) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/klear/frames.rb', line 32

def get frame_no
  (0 <= frame_no) or (raise "invalid negative frame no: #{frame_no}")
  (frame_no < count) or (raise "frame no out of bound: #{frame_no}")
  Klear::Frame.new(
    @columns, @rows, @data.slice(frame_no * @framesize, @framesize)
  )
end

#load(binary_string) ⇒ Object



17
18
19
20
# File 'lib/klear/frames.rb', line 17

def load binary_string
  @data = Data.read(binary_string).numbers
  self
end