Class: CWG::CwEncoding

Inherits:
Object
  • Object
show all
Defined in:
/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) construct_encodings



15
16
17
18
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 15

def construct_encodings
  @encodings = encode_a_n().merge(encode_0_2);
  @encodings.merge!(encode_3_space)
end

- (Object) encode(char)



20
21
22
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 20

def encode char
  encodings[char]
end

- (Object) encode_0_2



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 43

def encode_0_2
  {
    'o' => [:dash, :dash, :dash],
    'p' => [:dot, :dash, :dash, :dot],
    'q' => [:dash, :dash, :dot, :dash],
    'r' => [:dot, :dash, :dot],
    's' => [:dot, :dot, :dot],
    't' => [:dash],
    'u' => [:dot, :dot, :dash],
    'v' => [:dot, :dot, :dot, :dash],
    'w' => [:dot, :dash, :dash],
    'x' => [:dash, :dot, :dot, :dash],
    'y' => [:dash, :dot, :dash, :dash],
    'z' => [:dash, :dash, :dot, :dot],
    '1' => [:dot, :dash, :dash, :dash, :dash],
    '2' => [:dot, :dot, :dash, :dash, :dash]
  }
end

- (Object) encode_3_space



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 62

def encode_3_space
  {
    '3' => [:dot, :dot, :dot, :dash, :dash],
    '4' => [:dot, :dot, :dot, :dot, :dash],
    '5' => [:dot, :dot, :dot, :dot, :dot],
    '6' => [:dash, :dot, :dot, :dot, :dot],
    '7' => [:dash, :dash, :dot, :dot, :dot],
    '8' => [:dash, :dash, :dash, :dot, :dot],
    '9' => [:dash, :dash, :dash, :dash, :dot],
    '0' => [:dash, :dash, :dash, :dash, :dash],
    '.' => [:dot, :dash, :dot, :dash, :dot, :dash],
    ',' => [:dash, :dash, :dot, :dot, :dash, :dash],
    '=' => [:dash, :dot, :dot,:dot, :dash],
    '!' => [:dot, :dot, :dash, :dash, :dot],
    '/' => [:dash, :dot, :dot, :dash, :dot],
    '?' => [:dot, :dot, :dash, :dash, :dot, :dot],
    ' ' => []
  }
end

- (Object) encode_a_n



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 24

def encode_a_n
  {
    'a' => [:dot, :dash],
    'b' => [:dash, :dot, :dot, :dot],
    'c' => [:dash, :dot, :dash, :dot],
    'd' => [:dash, :dot, :dot],
    'e' => [:dot],
    'f' => [:dot, :dot, :dash, :dot],
    'g' => [:dash, :dash, :dot],
    'h' => [:dot, :dot, :dot, :dot],
    'i' => [:dot, :dot],
    'j' => [:dot, :dash, :dash, :dash],
    'k' => [:dash, :dot, :dash],
    'l' => [:dot, :dash, :dot, :dot],
    'm' => [:dash, :dash],
    'n' => [:dash, :dot]
  }
end

- (Object) encodings



11
12
13
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 11

def encodings
  @encodings ||= construct_encodings
end

- (Object) fetch(char)



7
8
9
# File '/Users/martyn/cw/cw_clone/lib/cw/cw_encoding.rb', line 7

def fetch char
  encode(char)
end