parsley-store 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ parsley-store.gemspec
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -11,4 +11,3 @@ Feature: Cached parsind of Scientific Names
11
11
  Given a clean local database
12
12
  When I parse a name "Homo sapiens sapiens (Linn.) 1758" two times
13
13
  Then second parse should be much faster
14
-
@@ -32,6 +32,7 @@ When /^I parse a name "([^"]*)" two times$/ do |name|
32
32
  end
33
33
 
34
34
  Then /^second parse should be much faster$/ do
35
+ # puts "%s/%s=%s", [@delta1, @delta2, @delta1/@delta2]
35
36
  (@delta1/@delta2).should > 10
36
37
  end
37
38
 
data/lib/parsley-store.rb CHANGED
@@ -8,21 +8,25 @@ class ParsleyStore
8
8
  SLAVE = 2
9
9
 
10
10
  def initialize
11
- @parser = ScientificNameParser.new
11
+ @parser = ScientificNameParser.new(local_db = LOCAL, slave_db = SLAVE)
12
12
  @local = Redis.new
13
- @local.select(LOCAL)
13
+ @local.select(local_db)
14
+ # slave replication is not set up yet, so I comment it out
15
+ # @slave = Redis.new
16
+ # @slave.select(slave_db)
14
17
  end
15
18
 
16
- def parse(scientific_name)
19
+ def parse(scientific_name, fast = false)
17
20
  stored = @local.get(scientific_name)
18
- return stored if stored
21
+ return (fast ? Marshal.load(stored) : JSON.load(stored)) if stored
19
22
  begin
20
23
  parsed = @parser.parse(scientific_name)
21
24
  rescue
22
25
  @parser = ScientificNameParser.new
23
26
  parsed = @parser.parse(scientific_name)
24
27
  end
25
- @local.set scientific_name, parsed
28
+ serialized = fast ? Marshal.dump(parsed) : parsed.to_json
29
+ @local.set scientific_name, serialized
26
30
  parsed
27
31
  end
28
32
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parsley-store
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmitry Mozzherin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-10 00:00:00 -04:00
18
+ date: 2010-09-13 00:00:00 -04:00
19
19
  default_executable: parsley-store
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency