Module: ObjectOrientedBeagleboneBlack::IO

Included in:
Led
Defined in:
lib/object_oriented_beaglebone_black/io.rb,
lib/object_oriented_beaglebone_black/io/value.rb,
lib/object_oriented_beaglebone_black/io/direction.rb

Defined Under Namespace

Modules: Direction, Value

Instance Method Summary collapse

Instance Method Details

#file_directory_pathObject



6
7
8
# File 'lib/object_oriented_beaglebone_black/io.rb', line 6

def file_directory_path
  raise "#{__method__} method must be implemented in the class including this module"
end

#read_from_io_file(filename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/object_oriented_beaglebone_black/io.rb', line 19

def read_from_io_file(filename)
  file_path = File.join(file_directory_path, filename)

  if File.exists?(file_path)
    file_content = nil
    # Using this instead of simple "File.open(file_path).read" in order to close file after reading. 
    File.open(file_path) do |file|
      file_content = file.read.strip
    end
    file_content
  end

end

#write_to_io_file(filename, value) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/object_oriented_beaglebone_black/io.rb', line 10

def write_to_io_file(filename, value)
  FileUtils.mkdir_p(file_directory_path, mode: 0700) unless Dir.exists?(file_directory_path)
  file_path = File.join(file_directory_path, filename)
  
  File.open(file_path, "w") do |file|
    file.write(value) 
  end
end