storage-da-es 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b26576d85679f76cc9234870a5bbea772cf15b82
4
- data.tar.gz: d4ec3e63608012c1513c53558aa71fe6b9a83f77
3
+ metadata.gz: d544452c612e6cdbb14e425c117a7bd09eb88a35
4
+ data.tar.gz: 61bfca678df2beb2160bc5d4d8d20face886ff4c
5
5
  SHA512:
6
- metadata.gz: 68e8fe842d0c5f35e298bf700bcd987bce85e3fd39d0170a5739b8d96194a02db6ca23709af3f23cf719020a78d46ccb515e29dabf497533b5b38cff14ba66d3
7
- data.tar.gz: 9f445b81c35bcb7716ba2cd67430fd4b6cba6442d30645c9cee60567da7de98c254eacc2c9f05d48fbaa3a994ea12347cb651d6f21ebf54375fb2c67e5d8b0ed
6
+ metadata.gz: 8c7711647bda37fe10113e9233e75ff50a6409c2e7b9bd4d468185793573b8930e7be60c3b98c035c805a93b4bad19e8613b7cd5772fe104be8fb77b56e9fcba
7
+ data.tar.gz: 4a74df71c7a082c6516f18d51341ee41b1068ebab06768991c330435d72fe6ea8e3322c13848508ebd528ece173a17b6231b7dceb162f9ca9cbb96c95690f879
data/.gitignore CHANGED
@@ -4,6 +4,5 @@
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
- /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in storage-da-es.gemspec
4
4
  gemspec
5
+
6
+ gem 'minitest', '5.9.0'
7
+ gem 'zip', '2.0.2'
8
+ gem 'simplecov', '0.12.0'
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
data/lib/storage/da/es.rb CHANGED
@@ -1,9 +1,141 @@
1
- require "storage/da/es/version"
1
+ require 'storage/da/es/version'
2
+ require 'rubygems'
3
+ require 'zip/zipfilesystem'
2
4
 
3
5
  module Storage
4
6
  module Da
5
7
  module Es
8
+ class Storage
9
+ def initialize
10
+ @root_node = assign_node('', [], false)
11
+ end
6
12
 
13
+ def add(string)
14
+ words = string.delete("' '||'\n'").split(',')
15
+ words.each do |word|
16
+ add_word(word)
17
+ end
18
+ self
19
+ end
20
+
21
+ def contains?(key)
22
+ current_node = @root_node
23
+ key.each_char.with_index do |c, i|
24
+ new_node = find_node_in_array(current_node[:childList], c)
25
+ if new_node
26
+ current_node = new_node
27
+ return true if current_node[:isEnd] && i == key.length-1
28
+ else
29
+ return false
30
+ end
31
+ end
32
+ end
33
+
34
+ def find(prefix)
35
+ raise ArgumentError, 'Length of prefix should be 3 or great' if prefix.length < 3
36
+ current_node = @root_node
37
+ prefix.each_char.with_index do |c, i|
38
+ new_node = find_node_in_array(current_node[:childList], c)
39
+ if new_node
40
+ current_node = new_node
41
+ return get_all_tail_by_node('', current_node, []).map{|tail| prefix.chop + tail} if i == prefix.length-1
42
+ else
43
+ return []
44
+ end
45
+ end
46
+ end
47
+
48
+ private def get_all_tail_by_node(tail, node, acc)
49
+ if node[:isEnd]
50
+ acc << tail + node[:label]
51
+ if node[:childList].any?
52
+ tail += node[:label]
53
+ node[:childList].each do |n|
54
+ get_all_tail_by_node(tail, n, acc)
55
+ end
56
+ else
57
+ return acc
58
+ end
59
+ else
60
+ tail += node[:label]
61
+ node[:childList].each do |n|
62
+ get_all_tail_by_node(tail, n, acc)
63
+ end
64
+ end
65
+ acc
66
+ end
67
+
68
+ def add_word(word)
69
+ current_node = @root_node
70
+ word.each_char.with_index do |c, i|
71
+ new_node = find_node_in_array(current_node[:childList], c)
72
+ if new_node
73
+ current_node = new_node
74
+ if i == word.length-1
75
+ current_node[:isEnd] = true
76
+ end
77
+ else
78
+ new_node = assign_node(c, [], i == word.length-1)
79
+ current_node[:childList].push(new_node)
80
+ current_node = new_node
81
+ end
82
+ end
83
+ end
84
+
85
+ private def find_node_in_array(list, label)
86
+ list.each do |n|
87
+ return n if (n[:label] == label)
88
+ end
89
+ nil
90
+ end
91
+
92
+ private def assign_node(label, child_list, is_end)
93
+ node = Hash.new
94
+ node[:label] = label
95
+ node[:childList] = child_list
96
+ node[:isEnd] = is_end
97
+ return node
98
+ end
99
+
100
+ def to_s
101
+ @root_node
102
+ end
103
+
104
+ def load_from_file(filename)
105
+ f = File.open(filename, 'r')
106
+ f.each_line do |line|
107
+ add(line)
108
+ end
109
+ f.close
110
+ self
111
+ end
112
+
113
+ def load_from_zip(zipfile)
114
+ Zip::ZipFile.open(zipfile) do |file|
115
+ file.each do |content|
116
+ text = file.read(content)
117
+ text.each_line do |line|
118
+ add(line)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def save_to_file(filename)
125
+ all_keys = get_all_tail_by_node('', @root_node, []).join(',')
126
+ file = File.open(filename, 'w')
127
+ file.write(all_keys)
128
+ file.close
129
+ end
130
+
131
+ def save_to_zip(zipfile_name)
132
+ filename = 'core/files/tmp/output.txt'
133
+ save_to_file(filename)
134
+ Zip::ZipFile.open(zipfile_name, Zip::ZipFile::CREATE) do |zipfile|
135
+ zipfile.add(filename,filename)
136
+ end
137
+ end
138
+ end
7
139
  end
8
140
  end
9
141
  end
@@ -1,7 +1,7 @@
1
1
  module Storage
2
2
  module Da
3
3
  module Es
4
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
7
7
  end
Binary file
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
26
  spec.bindir = "exe"
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
- spec.require_paths = ["lib"]
28
+ spec.require_paths = ['lib']
29
29
 
30
- spec.add_development_dependency "bundler", "~> 1.12"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency 'bundler', '~> 1.12'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'minitest', '~> 5.0'
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storage-da-es
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugene Safronov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,7 +61,6 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".travis.yml"
64
- - CODE_OF_CONDUCT.md
65
64
  - Gemfile
66
65
  - LICENSE.txt
67
66
  - README.md
@@ -70,6 +69,7 @@ files:
70
69
  - bin/setup
71
70
  - lib/storage/da/es.rb
72
71
  - lib/storage/da/es/version.rb
72
+ - pkg/storage-da-es-0.1.1.gem
73
73
  - storage-da-es.gemspec
74
74
  homepage: https://bitbucket.org/esafronoff/ruby-course
75
75
  licenses:
data/CODE_OF_CONDUCT.md DELETED
@@ -1,49 +0,0 @@
1
- # Contributor Code of Conduct
2
-
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
7
-
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
12
-
13
- Examples of unacceptable behavior by participants include:
14
-
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
18
- * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
22
-
23
- Project maintainers have the right and responsibility to remove, edit, or
24
- reject comments, commits, code, wiki edits, issues, and other contributions
25
- that are not aligned to this Code of Conduct, or to ban temporarily or
26
- permanently any contributor for other behaviors that they deem inappropriate,
27
- threatening, offensive, or harmful.
28
-
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
33
-
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
36
-
37
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at eugene.safronov@dataart.com. All
39
- complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
43
-
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
47
-
48
- [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/