spellcard 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b29c2d470a77f73c4bf00bc077a685a841a9cbc5
4
+ data.tar.gz: b5a7f8389f970307dd81fec3204ce96774f7f409
5
+ SHA512:
6
+ metadata.gz: e7aaade2cbdb6d77bc6be32b42ec377a1866be2bd15f8955ab09eba6b25c5ad6f1d6661f6be45046c94b970fe2387fefcf4dfd9d81184494b820f0a4b0441d79
7
+ data.tar.gz: 31ac6b7d21a4323b8fd3bba6b667c486c4a09aceaf3a0c84671ec71cbf2f83bfca4cda2f6961dc23ef533de3ad7fe0081a7f2e275cad9a6bbc39aac33c046e73
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spellcard.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'nokogiri'
8
+ gem 'active_support'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ikstrm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Spellcard
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spellcard'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install spellcard
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ lib = File.dirname(__FILE__) + '/../lib'
5
+ $:.unshift lib unless $:.include? lib
6
+
7
+ require 'spellcard'
8
+
9
+ Spellcard::setup
@@ -0,0 +1,23 @@
1
+ require "spellcard/version"
2
+ require "spellcard/parser"
3
+ require "spellcard/checker"
4
+
5
+ module Spellcard
6
+ def self.setup
7
+ if ARGV[0]
8
+ text = ''
9
+ File.open(ARGV[0]) do |f|
10
+ text = f.read
11
+ end
12
+
13
+ # parser = Parser.new
14
+ # text = parser.parse(text)
15
+
16
+ checker = Checker.new
17
+ checker.find_typo(text).each do |word|
18
+ puts word
19
+ end
20
+ else
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+ require 'active_support/core_ext/hash/conversions'
4
+
5
+ module Spellcard
6
+ class Checker
7
+ def find_typo(text)
8
+ array = word_array(text)
9
+ array.each.inject(Array.new) do |result, word|
10
+ if is_english_word(word) == false
11
+ result << word
12
+ else
13
+ result
14
+ end
15
+ end
16
+ end
17
+
18
+ def word_array(text)
19
+ text.split(' ').map { |word| word.gsub(/,/, "").gsub(/\./, "") }
20
+ end
21
+
22
+ def is_english_word(word)
23
+ begin
24
+ uri = 'http://public.dejizo.jp/NetDicV09.asmx/SearchDicItemLite?' +
25
+ 'Dic=EJdict&Scope=HEADWORD&Merge=AND&Prof=XHTML&PageSize=20' +
26
+ '&PageIndex=0&Match=EXACT&Word=' + word
27
+ doc = Nokogiri::XML(open(uri).read)
28
+ hash = Hash.from_xml(doc.to_s)
29
+ count = hash["SearchDicItemResult"]["TotalHitCount"].to_i
30
+ if count == 0
31
+ false
32
+ else
33
+ true
34
+ end
35
+ rescue
36
+ true
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module Spellcard
2
+ class Parser
3
+ def parse(source)
4
+ comment_mode = false
5
+ source.each_line.inject('') do |result, line|
6
+ if comment_mode == true
7
+ if line =~ /\*\//
8
+ comment_mode = false
9
+ result += line.gsub(/(.*)\*\/.*/, '\1')
10
+ else
11
+ result += line
12
+ end
13
+ else
14
+ if line =~ /\/\//
15
+ result += line.gsub(/.*\/\/(.*)/, '\1')
16
+ elsif line =~ /\/\*.*\*\//
17
+ result += line.gsub(/.*\/\*(.*)\*\/.*/, '\1')
18
+ elsif line =~ /\/\*/
19
+ comment_mode = true
20
+ result += line.gsub(/.*\/\*(.*)/, '\1')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Spellcard
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'spellcard'
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ module Spellcard
4
+ describe Checker do
5
+ let(:checker) { Checker.new }
6
+
7
+ describe "#find_typo" do
8
+ context "given English sentences that contain no misspelled word" do
9
+ it "returns ''" do
10
+ text = checker.find_typo('This is a pen.')
11
+ text.should == []
12
+ end
13
+ end
14
+
15
+ context "given English sentences that contain one misspelled word" do
16
+ it "returns the misspelled word" do
17
+ text = checker.find_typo('Thiis is a pen.')
18
+ text.should == ['Thiis']
19
+ end
20
+ end
21
+
22
+ context "given the string that has no mean" do
23
+ it "returns the string" do
24
+ text = checker.find_typo('Thiis Thiis')
25
+ text.should == ['Thiis', 'Thiis']
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#word_array" do
31
+ context "given English sentence" do
32
+ it "returns the word array in the sentence" do
33
+ array = checker.word_array('Hello, I can fly.')
34
+ array.should == ['Hello', 'I', 'can', 'fly']
35
+ end
36
+ end
37
+
38
+ context "given wrong English sentence" do
39
+ it "returns the word array in the sentence" do
40
+ array = checker.word_array('Thiis is a pen.')
41
+ array.should == ['Thiis', 'is', 'a', 'pen']
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "#is_english_word" do
47
+ context "given English word" do
48
+ it "returns true" do
49
+ checker.is_english_word('this').should == true
50
+ end
51
+ end
52
+
53
+ context "given not English word" do
54
+ it "returns false" do
55
+ checker.is_english_word('Thiis').should == false
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ module Spellcard
4
+ describe Parser do
5
+ let(:parser) { Parser.new }
6
+
7
+ describe "#parse" do
8
+ context "given one-line C source code with // comment" do
9
+ it "returns comment" do
10
+ text = parser.parse('int main(void) { printf("test"); } //comment')
11
+ text.should == 'comment'
12
+ end
13
+ end
14
+
15
+ context "given multi-line C source code with // comment" do
16
+ it "returns comment" do
17
+ text = parser.parse("code //first-line\ncode //second-line")
18
+ text.should == "first-line\nsecond-line"
19
+ end
20
+ end
21
+
22
+ context "given one-line C source code with /* */ comment" do
23
+ it "returns comment" do
24
+ text = parser.parse('foo /* hoge */ bar')
25
+ text.should == ' hoge '
26
+ end
27
+ end
28
+
29
+ context "given multi-line C source code with /* */ comment" do
30
+ it "returns comment" do
31
+ text = parser.parse("code /*first-line\nsecond-line\nthird-line*/ code")
32
+ text.should == "first-line\nsecond-line\nthird-line"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spellcard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spellcard"
8
+ spec.version = Spellcard::VERSION
9
+ spec.authors = ["ikstrm"]
10
+ spec.email = ["igzarion.1993@gmail.com"]
11
+ spec.description = %q{Find misspelled comment in your source code}
12
+ spec.summary = %q{Find misspelled comment in your source code}
13
+ spec.homepage = "https://github.com/ikstrm/spellcard"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["spellcard"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "nokogiri"
24
+ spec.add_development_dependency "active_support"
25
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spellcard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ikstrm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: active_support
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Find misspelled comment in your source code
70
+ email:
71
+ - igzarion.1993@gmail.com
72
+ executables:
73
+ - spellcard
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/spellcard
83
+ - lib/spellcard.rb
84
+ - lib/spellcard/checker.rb
85
+ - lib/spellcard/parser.rb
86
+ - lib/spellcard/version.rb
87
+ - spec/spec_helper.rb
88
+ - spec/spellcard/checker_spec.rb
89
+ - spec/spellcard/parser_spec.rb
90
+ - spellcard.gemspec
91
+ homepage: https://github.com/ikstrm/spellcard
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.0
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Find misspelled comment in your source code
115
+ test_files:
116
+ - spec/spec_helper.rb
117
+ - spec/spellcard/checker_spec.rb
118
+ - spec/spellcard/parser_spec.rb