morsecode 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/morsecode.rb +7 -5
- metadata +1 -1
data/lib/morsecode.rb
CHANGED
@@ -7,18 +7,20 @@ require 'rexml/document'
|
|
7
7
|
class MorseCode
|
8
8
|
include REXML
|
9
9
|
|
10
|
-
def initialize()
|
10
|
+
def initialize(x)
|
11
11
|
buffer = File.open(File.dirname(__FILE__) + '/morsecode.xml','r').read
|
12
12
|
doc = Document.new(buffer)
|
13
13
|
@h = Hash[XPath.match(doc.root, 'records/code').map{|x| x.map{|name| name.text.to_s}}]
|
14
|
+
|
15
|
+
@x = x
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
+
def to_s
|
19
|
+
@x.split(/4/).map{|code| @h[code]}.join()
|
18
20
|
end
|
19
21
|
|
20
|
-
def
|
21
|
-
|
22
|
+
def to_mc
|
23
|
+
@x.split(//).map{|char| @h.invert[char]}.join('4')
|
22
24
|
end
|
23
25
|
|
24
26
|
end
|