Module: Wol::ParseFile
- Defined in:
- lib/wol/parsefile.rb
Overview
Parse a text file containing hardware addresses, host names/addresses, and port numbers
Class Method Summary collapse
-
.parse(text) ⇒ Object
Parse a given string and return a hash containing the results.
-
.read_and_parse_file(file) ⇒ Object
Read a file and then parse its contents.
Class Method Details
.parse(text) ⇒ Object
Parse a given string and return a hash containing the results
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wol/parsefile.rb', line 12 def self.parse(text) hosts = [] text.each_line do |line| unless line.match(/^#/) || line.strip.empty? mac, address, port = line.strip.split port ||= 9 host ||= "255.255.255.255" if check_mac(mac) && check_host(address) hosts << { :mac => mac, :address => address, :port => sanitize_port(port)} end end end return hosts end |
.read_and_parse_file(file) ⇒ Object
Read a file and then parse its contents
31 32 33 |
# File 'lib/wol/parsefile.rb', line 31 def self.read_and_parse_file(file) parse(read_file(file)) end |