Class: Nineteen::Eighty::Two::Spectrum

Inherits:
Object
  • Object
show all
Defined in:
lib/nineteen/eighty/two/spectrum.rb

Constant Summary collapse

CHARACTERS =
YAML.load_file File.join File.dirname(__FILE__), '..', '..', '..', '..', 'config', 'characters.yml'

Class Method Summary collapse

Class Method Details

.[](*text) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/nineteen/eighty/two/spectrum.rb', line 7

def self.[] *text
  a = []
  text.each do |t|
    a += Spectrum.linify(t.chars.map { |c| Spectrum.get(c) })
  end

  a
end

.bits(number) ⇒ Object



31
32
33
34
35
# File 'lib/nineteen/eighty/two/spectrum.rb', line 31

def self.bits number
  (0..7).map do |i|
    number[i]
  end.reverse
end

.get(key) ⇒ Object



26
27
28
29
# File 'lib/nineteen/eighty/two/spectrum.rb', line 26

def self.get key
  key = ' ' unless CHARACTERS[key]
  CHARACTERS[key].map { |b| Spectrum.bits(b) }
end

.linify(*list) ⇒ Object



37
38
39
# File 'lib/nineteen/eighty/two/spectrum.rb', line 37

def self.linify *list
  Matrix.columns(list.first).to_a.map { |l| l.flatten }
end

.to_hObject



16
17
18
19
20
21
22
23
24
# File 'lib/nineteen/eighty/two/spectrum.rb', line 16

def self.to_h
  h = {}

  CHARACTERS.keys.each do |c|
    h[c.to_sym] = get(c)
  end

  h
end