Class: Samantha::Hex_Aggregator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHex_Aggregator

Returns a new instance of Hex_Aggregator.



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

def initialize
  @hexes = []
end

Instance Attribute Details

#hexesObject

Returns the value of attribute hexes.



4
5
6
# File 'lib/hex_aggregator.rb', line 4

def hexes
  @hexes
end

Instance Method Details

#find_colors_in_directory(directory) ⇒ Object



10
11
12
# File 'lib/hex_aggregator.rb', line 10

def find_colors_in_directory(directory)
  Dir["#{directory}/*"].map { |file| find_colors_in_file(file) }
end

#find_colors_in_file(file) ⇒ Object



14
15
16
17
18
# File 'lib/hex_aggregator.rb', line 14

def find_colors_in_file(file)
  File.open(file) do |file_contents|
    file_contents.each_line { |line| find_colors_in_line(line) }
  end
end

#find_colors_in_line(line) ⇒ Object



20
21
22
# File 'lib/hex_aggregator.rb', line 20

def find_colors_in_line(line)
  line.scan(/\B#[0-9a-fA-f]{3,6}\b/).each {|hex| @hexes.push(hex)}
end