Class: CanFrameSet

Inherits:
Object
  • Object
show all
Defined in:
lib/retrotoolkit/can_frame_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frames) ⇒ CanFrameSet

Returns a new instance of CanFrameSet.



5
6
7
# File 'lib/retrotoolkit/can_frame_set.rb', line 5

def initialize frames
  @frames = frames
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames.



3
4
5
# File 'lib/retrotoolkit/can_frame_set.rb', line 3

def frames
  @frames
end

Instance Method Details

#find_by_identifier(identifier) ⇒ Object



17
18
19
# File 'lib/retrotoolkit/can_frame_set.rb', line 17

def find_by_identifier identifier
  @frames.select { |f| f.identifier == identifier }
end

#find_by_value(value) ⇒ Object



21
22
23
# File 'lib/retrotoolkit/can_frame_set.rb', line 21

def find_by_value value
  @frames.select { |f| f.match(value) }
end

#formatted_outputObject



29
30
31
# File 'lib/retrotoolkit/can_frame_set.rb', line 29

def formatted_output
  @frames.map { |f| f.formatted_output }.join("\n")
end

#identifiersObject



9
10
11
12
13
14
15
# File 'lib/retrotoolkit/can_frame_set.rb', line 9

def identifiers
  identifiers = []
  @frames.each do |f|
    identifiers << f.identifier unless identifiers.include?(f.identifier)
  end
  identifiers
end

#match_identifier_with_value(id, value) ⇒ Object



25
26
27
# File 'lib/retrotoolkit/can_frame_set.rb', line 25

def match_identifier_with_value id, value
  find_by_value(value) & find_by_identifier(id)
end

#write(file) ⇒ Object



33
34
35
36
37
# File 'lib/retrotoolkit/can_frame_set.rb', line 33

def write file
  File.open file, 'w' do |f|
    f.write formatted_output
  end  
end