dancroak-webster 0.2.1 → 0.3.0

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.
Files changed (5) hide show
  1. data/Rakefile +12 -0
  2. data/VERSION.yml +2 -2
  3. data/lib/open_safely.rb +15 -0
  4. data/lib/webster.rb +7 -2
  5. metadata +2 -1
data/Rakefile CHANGED
@@ -1,4 +1,16 @@
1
1
  require 'rake'
2
+ require 'rake/testtask'
3
+ require 'date'
4
+
5
+ test_files_pattern = 'test/**/*_test.rb'
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib'
8
+ t.pattern = test_files_pattern
9
+ t.verbose = false
10
+ end
11
+
12
+ desc "Run the test suite"
13
+ task :default => :test
2
14
 
3
15
  begin
4
16
  require 'rubygems'
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 1
2
+ patch: 0
3
3
  major: 0
4
- minor: 2
4
+ minor: 3
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ require 'tempfile'
3
+
4
+ class File
5
+ def File.open_safely(path)
6
+ result, temp_path = nil, nil
7
+ Tempfile.open("#{$0}-#{path.hash}") do |file|
8
+ result = yield file
9
+ temp_path = file.path
10
+ end
11
+ FileUtils.move temp_path, path
12
+ result
13
+ end
14
+ end
15
+
data/lib/webster.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # require "open_safely"
2
+
1
3
  class Webster
2
4
 
3
5
  DICTIONARY_FILE = File.join(File.dirname(__FILE__), "words")
@@ -5,11 +7,14 @@ class Webster
5
7
  attr_accessor :dictionary
6
8
 
7
9
  def initialize
8
- @dictionary = IO.readlines DICTIONARY_FILE
10
+ @dictionary = []
11
+ File.open(DICTIONARY_FILE) do |file|
12
+ @dictionary = file.readlines.collect { |word| word.chomp }
13
+ end
9
14
  end
10
15
 
11
16
  def random
12
- dictionary[rand(dictionary.size)].chomp
17
+ dictionary[rand(dictionary.size)]
13
18
  end
14
19
 
15
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dancroak-webster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -25,6 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - README.textile
27
27
  - VERSION.yml
28
+ - lib/open_safely.rb
28
29
  - lib/webster.rb
29
30
  - lib/words
30
31
  - test/webster_test.rb