Class: CW::Encoding
Constant Summary
Constants included
from FileDetails
FileDetails::ABBREVIATIONS, FileDetails::AUDIO_DIR, FileDetails::BOOKMARK_FILE, FileDetails::CALLS, FileDetails::CALLS_FILENAME, FileDetails::CODE, FileDetails::CODE_FILENAME, FileDetails::CONFIG_FILENAME, FileDetails::CONFIG_PATH, FileDetails::DASH_FILENAME, FileDetails::DATA, FileDetails::DEF_AUDIO_FILENAME, FileDetails::DICT_DIR, FileDetails::DICT_FILENAME, FileDetails::DOT_AUDIO_DIR, FileDetails::DOT_CW_DIR, FileDetails::DOT_FILENAME, FileDetails::E_SPACE_FILENAME, FileDetails::HERE, FileDetails::Q_CODES, FileDetails::ROOT, FileDetails::SPACE_FILENAME, FileDetails::TEXT, FileDetails::USER_CONFIG_PATH, FileDetails::WORK_DIR
Instance Method Summary
collapse
#audio_dir, #audio_filename, #dash_path, #default_audio_dir, #dot_audio_dir, #dot_cw_dir, #dot_path, #e_space_path, #init_filenames, #process_audio_dir, #process_dot_audio, #process_dot_cw, #progress_file, #space_path, #user_audio_dir
Constructor Details
Returns a new instance of Encoding.
8
9
10
|
# File 'lib/cw/encoding.rb', line 8
def initialize
@char_lookup = "*eish54v*3uf***!2arl***+*wp**j*1tndb6=x/*kc**y**mgz7*q**o*8**90*".split('').map(&:to_sym)
end
|
Instance Method Details
#encodings ⇒ Object
12
13
14
15
16
17
|
# File 'lib/cw/encoding.rb', line 12
def encodings
if @encodings.nil?
@encodings = load_code
end
@encodings
end
|
#fast_match(code) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/cw/encoding.rb', line 42
def fast_match code
index = 0
dash_jump = 64
code.each do |ele|
dash_jump = dash_jump / 2
index = index + ((ele == :dot) ? 1 : dash_jump)
end
return @char_lookup[index].to_s
end
|
#fetch(char) ⇒ Object
25
26
27
|
# File 'lib/cw/encoding.rb', line 25
def fetch char
encodings[char]
end
|
#fetch_char(code) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/cw/encoding.rb', line 53
def fetch_char code
length = code.length
case length
when 1..5
return ' ' if code == [:space]
return encodings.key(code)
when 0
return '*'
else
temp = encodings.key(code)
return temp if temp
return '*' unless temp
end
end
|
#load_code ⇒ Object
19
20
21
22
23
|
# File 'lib/cw/encoding.rb', line 19
def load_code
File.open(CODE_FILENAME, "r") do |code|
YAML::load(code)
end
end
|
#match_elements(arg) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cw/encoding.rb', line 29
def match_elements arg
chars = []
encodings.each_pair do |key, value|
chars << key unless value.include?(:dot) if arg[0] == :dashes
chars << key unless value.include?(:dash) if arg[0] == :dots
chars << key if ( value.size < arg[1] ) if arg[0] == :less_than
chars << key if ( value.size > arg[1] ) if arg[0] == :greater_than
chars << key if ( value.size == arg[1] ) if arg[0] == :size
chars.delete(' ')
end
chars
end
|