cw_parser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.2.1"
11
+ gem "jeweler", "~> 1.8.4"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.5)
11
+ rake (10.0.1)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.2.1)
20
+ jeweler (~> 1.8.4)
21
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 wsugg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,20 @@
1
+ = cw_parser
2
+
3
+ Takes Morse Code and translates it to text and vise versa.
4
+
5
+ gem install cw_parser-0.0.1.gem
6
+ == Contributing to cw_parser
7
+
8
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
9
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
10
+ * Fork the project.
11
+ * Start a feature/bugfix branch.
12
+ * Commit and push until you are happy with your contribution.
13
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
14
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2012 wsugg. See LICENSE.txt for
19
+ further details.
20
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "cw_parser"
18
+ gem.homepage = "http://github.com/wsugg/cw_parser"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Takes Morse Code and translates it to text and vise versa}
21
+ gem.description = %Q{Takes Morse Code and translates it to text and vise versa. Fall UW Ruby Class Final Project.}
22
+ gem.email = "sugg.will@gmail.com"
23
+ gem.authors = ["wsugg"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ task :default => :test
29
+
30
+ require 'rdoc/task'
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
+
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "cw_parser #{version}"
36
+ rdoc.rdoc_files.include('README*')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,74 @@
1
+ #!usr/bin/env ruby
2
+ #require "rubygems"
3
+ #require "bundler/setup"
4
+ require '../lib/cw_parse_text.rb'
5
+ require '../lib/cw_parse_code.rb'
6
+
7
+
8
+ #args to cw_parser: text | code, file, filepath, play code sounds (implement sound later)
9
+
10
+ class CW_Parser
11
+ include CW_Parse_Text
12
+ include CW_Parse_Code
13
+
14
+ attr_reader :morse_code
15
+ attr_accessor :mode, :sound, :filepath
16
+
17
+ def initialize(mode=[:text],filepath="",sound="no")
18
+ @mode = mode
19
+ @filepath = filepath
20
+ @sound = sound
21
+
22
+ puts "filepath: #{filepath}"
23
+ @morse_code = {}
24
+
25
+ f = File.open("../bin/morsecode.txt", "r")
26
+ f.each{|l| l.split(/\=/); @morse_code.store(l[0],l[2..10].chomp)}
27
+ #@morse_code.each{|i| puts i} #for debugging
28
+ end
29
+
30
+ def translate_file(path="")
31
+ if true == File.exist?(path)
32
+ puts "path: #{path}"
33
+ puts "mode= #{@mode}"
34
+ ftranslate = File.read(path)
35
+ ftranslate.gsub!(/\n/, " ")
36
+
37
+ if @mode == :text
38
+ puts ftranslate.inspect
39
+ parse_text(ftranslate)
40
+ else
41
+ puts ftranslate.inspect
42
+ parse_code(ftranslate)
43
+ end
44
+ else "#{path} does not exsist"
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+
51
+
52
+ #puts ftranslate
53
+ #ftranslate.each{|line| puts "text line:" ;line = line.chop; parse_text(line)}
54
+ =begin
55
+ if true == File.exist?(filepath)
56
+ puts filepath
57
+ puts "text_symbol:#{:text} code_or_text:#{code_or_text}"
58
+ if code_or_text == [:text]
59
+ ftranslate = File.open(filepath, "r")
60
+ ftranslate.each{|line| line = line.chop; parse_text(line)}
61
+ else ftranslate.each{|line| parse_code(line)}
62
+ end
63
+
64
+ elsif code_or_text == [:text]
65
+ puts :text
66
+ #code_or_text = "this is the text to translate!"
67
+ #parse_text(code_or_text)
68
+
69
+ elsif code_or_text == [:code]
70
+ puts :code
71
+ #code = "this"
72
+ parse_code(code)
73
+ end
74
+ =end
data/bin/morsecode.txt ADDED
@@ -0,0 +1,38 @@
1
+ A=.-
2
+ B=-...
3
+ C=-.-.
4
+ D=-..
5
+ E=.
6
+ F=..-.
7
+ G=--.
8
+ H=....
9
+ I=..
10
+ J=.---
11
+ K=-.-
12
+ L=.-..
13
+ M=--
14
+ N=-.
15
+ O=---
16
+ P=.--.
17
+ Q=--.-
18
+ R=.-.
19
+ S=...
20
+ T=-
21
+ U=..-
22
+ V=...-
23
+ W=.--
24
+ X=-..-
25
+ Y=-.--
26
+ Z=--..
27
+ 1=.----
28
+ 2=..---
29
+ 3=...--
30
+ 4=....-
31
+ 5=.....
32
+ 6=-....
33
+ 7=--...
34
+ 8=---..
35
+ 9=----.
36
+ 0=-----
37
+ =
38
+ =
@@ -0,0 +1,38 @@
1
+ A=.-
2
+ B=-...
3
+ C=-.-.
4
+ D=-..
5
+ E=.
6
+ F=..-.
7
+ G=--.
8
+ H=....
9
+ I=..
10
+ J=.---
11
+ K=-.-
12
+ L=.-..
13
+ M=--
14
+ N=-.
15
+ O=---
16
+ P=.--.
17
+ Q=--.-
18
+ R=.-.
19
+ S=...
20
+ T=-
21
+ U=..-
22
+ V=...-
23
+ W=.--
24
+ X=-..-
25
+ Y=-.--
26
+ Z=--..
27
+ 1=.----
28
+ 2=..---
29
+ 3=...--
30
+ 4=....-
31
+ 5=.....
32
+ 6=-....
33
+ 7=--...
34
+ 8=---..
35
+ 9=----.
36
+ 0=-----
37
+ =
38
+ =
data/cw_parser.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cw_parser"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["wsugg"]
12
+ s.date = "2012-12-11"
13
+ s.description = "Takes Morse Code and translates it to text and vise versa. Fall UW Ruby Class Final Project."
14
+ s.email = "sugg.will@gmail.com"
15
+ s.executables = ["cw_parser_init.rb", "morsecode.txt", "morsecode.txt~"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/cw_parser_init.rb",
29
+ "bin/morsecode.txt",
30
+ "cw_parser-0.0.1.gem",
31
+ "cw_parser.gemspec",
32
+ "lib/cw_parse_code.rb",
33
+ "lib/cw_parse_text.rb",
34
+ "lib/cw_parser.rb",
35
+ "lib/test.txt",
36
+ "lib/test_code.txt",
37
+ "spec/cw_parser_spec.rb",
38
+ "test/test_cw_parser.rb"
39
+ ]
40
+ s.homepage = "http://github.com/wsugg/cw_parser"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.24"
44
+ s.summary = "Takes Morse Code and translates it to text and vise versa"
45
+
46
+ if s.respond_to? :specification_version then
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
51
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.1"])
52
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
53
+ else
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.2.1"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.2.1"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,17 @@
1
+ #!usr/bin/env ruby
2
+
3
+ module CW_Parse_Code
4
+
5
+ def parse_code(code_to_translate)
6
+ puts "code_to_translate: #{code_to_translate}"
7
+ code_to_translate_ary = Array.new
8
+ result_str = ""
9
+
10
+ code_to_translate_ary = code_to_translate.split(' ')
11
+ #puts "code to translate array: #{code_to_translate_ary}" #for debugging
12
+ code_to_translate_ary.each{|a| result_str << @morse_code.key(a)}
13
+ puts "Code:#{code_to_translate_ary} Morse Code:#{result_str}"
14
+ result_str
15
+
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ #!usr/bin/env ruby
2
+
3
+ module CW_Parse_Text
4
+
5
+ def parse_text(text_to_translate)
6
+ text_to_translate_ary = Array.new
7
+ result_str = ""
8
+
9
+ text_to_translate_ary = text_to_translate.upcase.chars.to_a
10
+ #puts "Text:#{text_to_translate_ary}" #for debugging
11
+ text_to_translate_ary.each{|a| result_str << " " << @morse_code.fetch(a)} #puts result_str}
12
+ puts "Text:#{text_to_translate_ary} Morse Code:#{result_str}"
13
+ result_str
14
+ end
15
+ end
data/lib/cw_parser.rb ADDED
File without changes
data/lib/test.txt ADDED
@@ -0,0 +1,2 @@
1
+ This is the text to translate in the txt file
2
+ this is the second line to translate
data/lib/test_code.txt ADDED
@@ -0,0 +1 @@
1
+ - .... .. ... .. ... - .... . - . -..- - - --- - .-. .- -. ... .-.. .- - . .. -. - .... . - -..- - ..-. .. .-.. . - .... .. ... .. ... - .... . ... . -.-. --- -. -.. .-.. .. -. . - --- - .-. .- -. ... .-.. .- - .
@@ -0,0 +1,53 @@
1
+ require '~/Fall2012FinalProj/cw_parser/bin/cw_parser_init.rb'
2
+ #puts File.dirname(__FILE__)
3
+ #puts" #{File.dirname("/bin/cw_parser_init.rb")}"
4
+ #puts require "#{File.dirname('../'__FILE__)}/cw_parser_init.rb"
5
+
6
+ describe CW_Parser do
7
+ testfile = "../lib/test.txt"
8
+ test_code_file = "../lib/test_code.txt"
9
+
10
+ before do
11
+ @cwp = CW_Parser.new(:text, testfile, "no") #:code
12
+ end
13
+
14
+ it "should create morse code hash" do
15
+ @cwp.morse_code.should be_true
16
+ end
17
+
18
+ it "should take code, text as the first arg" do
19
+ @cwp.mode.should eq :text
20
+ end
21
+
22
+ it "should take a filepath arg to open a file to translate from text" do
23
+ @cwp.filepath.should eq testfile
24
+ end
25
+
26
+ it "should have a alphabet and morsecode hash" do
27
+ @cwp.morse_code["A"].should eq ".-"
28
+ end
29
+
30
+ it "it should parse text into morse code" do
31
+ text = "this is"
32
+ @cwp.parse_text(text).should eq " - .... .. ... .. ..."
33
+ end
34
+
35
+ it "should parse morse code into text" do
36
+ code = "- .... .. ... .. ..."
37
+ @cwp.parse_code(code).should eq "THISIS"
38
+ end
39
+
40
+ it "should open a file and translate the text" do
41
+ @cwp.mode = :text
42
+ result = ""
43
+ result = @cwp.translate_file(testfile)
44
+ result.should eq " - .... .. ... .. ... - .... . - . -..- - - --- - .-. .- -. ... .-.. .- - . .. -. - .... . - -..- - ..-. .. .-.. . - .... .. ... .. ... - .... . ... . -.-. --- -. -.. .-.. .. -. . - --- - .-. .- -. ... .-.. .- - . "
45
+ end
46
+
47
+ it "should open a file and translate the text" do
48
+ @cwp.mode = :code
49
+ result = ""
50
+ result = @cwp.translate_file(test_code_file)
51
+ result.should eq "THISISTHETEXTTOTRANSLATEINTHETXTFILETHISISTHESECONDLINETOTRANSLATE"
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCwParser < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cw_parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - wsugg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.12'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.12'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.1
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ description: Takes Morse Code and translates it to text and vise versa. Fall UW Ruby
63
+ Class Final Project.
64
+ email: sugg.will@gmail.com
65
+ executables:
66
+ - cw_parser_init.rb
67
+ - morsecode.txt
68
+ - morsecode.txt~
69
+ extensions: []
70
+ extra_rdoc_files:
71
+ - LICENSE.txt
72
+ - README.rdoc
73
+ files:
74
+ - .document
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - LICENSE.txt
78
+ - README.rdoc
79
+ - Rakefile
80
+ - VERSION
81
+ - bin/cw_parser_init.rb
82
+ - bin/morsecode.txt
83
+ - cw_parser-0.0.1.gem
84
+ - cw_parser.gemspec
85
+ - lib/cw_parse_code.rb
86
+ - lib/cw_parse_text.rb
87
+ - lib/cw_parser.rb
88
+ - lib/test.txt
89
+ - lib/test_code.txt
90
+ - spec/cw_parser_spec.rb
91
+ - test/test_cw_parser.rb
92
+ - bin/morsecode.txt~
93
+ homepage: http://github.com/wsugg/cw_parser
94
+ licenses:
95
+ - MIT
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.24
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Takes Morse Code and translates it to text and vise versa
118
+ test_files: []