rdayone 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +3 -0
- data/lib/rdayone/entry.rb +4 -1
- data/lib/rdayone/entry_list.rb +5 -2
- data/lib/rdayone/finder.rb +16 -2
- data/lib/rdayone/journal.rb +2 -2
- data/lib/rdayone/version.rb +1 -1
- data/spec/fixtures/photos/02B82925942747709E1DF0518A650E1B.jpg +0 -0
- data/spec/rdayone/entry_list_spec.rb +9 -1
- data/spec/rdayone/entry_spec.rb +13 -0
- data/spec/rdayone/finder_spec.rb +22 -1
- data/spec/rdayone/journal_spec.rb +11 -6
- data/spec/spec_helper.rb +2 -2
- metadata +7 -4
data/.travis.yml
ADDED
data/README.md
CHANGED
data/lib/rdayone/entry.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module Rdayone
|
2
2
|
class Entry
|
3
|
-
|
3
|
+
attr_reader :photo
|
4
|
+
|
5
|
+
def initialize(plist_hash = {}, photo = nil)
|
4
6
|
@plist_hash = plist_hash
|
7
|
+
@photo = photo
|
5
8
|
@attribute_mappings = {
|
6
9
|
text: "Entry Text",
|
7
10
|
creation_date: "Creation Date",
|
data/lib/rdayone/entry_list.rb
CHANGED
@@ -4,16 +4,19 @@ module Rdayone
|
|
4
4
|
class EntryList
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
def initialize(entry_paths)
|
7
|
+
def initialize(entry_paths, finder)
|
8
8
|
@entry_paths = entry_paths
|
9
9
|
@entry_cache = {}
|
10
|
+
@finder = finder
|
10
11
|
end
|
11
12
|
|
12
13
|
def fetch(index)
|
13
14
|
raise ArgumentError if index > @entry_paths.length
|
14
15
|
entry = @entry_cache[index]
|
15
16
|
unless entry
|
16
|
-
|
17
|
+
uuid = @finder.uuid_from_path(@entry_paths[index])
|
18
|
+
photo = @finder.find_photo_for(uuid)
|
19
|
+
entry = Rdayone::Entry.new(Plist::parse_xml(@entry_paths[index]), photo)
|
17
20
|
@entry_cache[index] = entry
|
18
21
|
end
|
19
22
|
entry
|
data/lib/rdayone/finder.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
module Rdayone
|
2
2
|
class Finder
|
3
|
-
|
4
|
-
|
3
|
+
attr_reader :path
|
4
|
+
|
5
|
+
def initialize(path)
|
6
|
+
@path = path
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_entries
|
10
|
+
EntryList.new(Dir["#{@path}/entries/*.doentry"], self)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_photo_for(uuid)
|
14
|
+
Dir["#{@path}/photos/#{uuid}.jpg"].map { |f| File.expand_path(f) }[0]
|
15
|
+
end
|
16
|
+
|
17
|
+
def uuid_from_path(path)
|
18
|
+
File.basename(path, ".*")
|
5
19
|
end
|
6
20
|
end
|
7
21
|
end
|
data/lib/rdayone/journal.rb
CHANGED
@@ -2,10 +2,10 @@ module Rdayone
|
|
2
2
|
class Journal
|
3
3
|
attr_reader :file_path, :entries, :finder
|
4
4
|
|
5
|
-
def initialize(file_path, finder = Rdayone::Finder)
|
5
|
+
def initialize(file_path, finder = Rdayone::Finder.new(file_path))
|
6
6
|
@file_path = file_path
|
7
7
|
@finder = finder
|
8
|
-
@entries = finder.
|
8
|
+
@entries = finder.find_entries
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/rdayone/version.rb
CHANGED
File without changes
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rdayone::EntryList do
|
4
|
-
|
4
|
+
let(:finder) { double("finder").as_null_object }
|
5
|
+
|
6
|
+
subject { Rdayone::EntryList.new(entry_fixture_paths, finder) }
|
5
7
|
|
6
8
|
context "entry fetching" do
|
7
9
|
it "returns the nth entry when used like an array" do
|
@@ -17,6 +19,12 @@ describe Rdayone::EntryList do
|
|
17
19
|
it "throws an error if the index is out of range" do
|
18
20
|
expect { subject[100] }.to raise_error(ArgumentError)
|
19
21
|
end
|
22
|
+
|
23
|
+
it "uses the finder to pass in the full path to the photo" do
|
24
|
+
finder.stub(:uuid_from_path).and_return("uuid")
|
25
|
+
finder.should_receive(:find_photo_for).with("uuid")
|
26
|
+
expect(subject[0].photo).to_not be_nil
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
context "enumerating" do
|
data/spec/rdayone/entry_spec.rb
CHANGED
@@ -5,6 +5,19 @@ describe Rdayone::Entry do
|
|
5
5
|
it "can occur with no arguments" do
|
6
6
|
entry = Rdayone::Entry.new
|
7
7
|
end
|
8
|
+
|
9
|
+
context "with photo" do
|
10
|
+
let(:photo) { double("photo") }
|
11
|
+
|
12
|
+
it "can take an optional photo argument" do
|
13
|
+
entry = Rdayone::Entry.new({}, photo)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "exposes that photo via an attribute" do
|
17
|
+
entry = Rdayone::Entry.new({}, photo)
|
18
|
+
expect(entry.photo).to eq(photo)
|
19
|
+
end
|
20
|
+
end
|
8
21
|
end
|
9
22
|
|
10
23
|
context "basic parsing" do
|
data/spec/rdayone/finder_spec.rb
CHANGED
@@ -1,8 +1,29 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rdayone::Finder do
|
4
|
+
subject { Rdayone::Finder.new('spec/fixtures') }
|
5
|
+
|
4
6
|
it "finds all entries in the given directory" do
|
5
|
-
result =
|
7
|
+
result = subject.find_entries
|
6
8
|
expect(result.count).to be > 0
|
7
9
|
end
|
10
|
+
|
11
|
+
it "finds the photo corresponding to an entry (if one exists)" do
|
12
|
+
photo = subject.find_photo_for("02B82925942747709E1DF0518A650E1B")
|
13
|
+
expect(photo).to eq(photo_fixture_path_for_uuid("02B82925942747709E1DF0518A650E1B"))
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns nil if there is no photo" do
|
17
|
+
photo = subject.find_photo_for("not_there")
|
18
|
+
expect(photo).to be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "passes itself into the new entry list" do
|
22
|
+
Rdayone::EntryList.should_receive(:new).with(kind_of(Array), subject)
|
23
|
+
subject.find_entries
|
24
|
+
end
|
25
|
+
|
26
|
+
it "can extract a uuid from an entry path" do
|
27
|
+
expect(subject.uuid_from_path("spec/fixtures/entries/uuid.doentry")).to eq("uuid")
|
28
|
+
end
|
8
29
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Rdayone::Journal do
|
4
|
-
|
4
|
+
context "loading" do
|
5
5
|
let(:finder) do
|
6
6
|
f = double("finder")
|
7
|
-
f.stub(:
|
7
|
+
f.stub(:find_entries) { [double("entry")] }
|
8
8
|
f
|
9
9
|
end
|
10
10
|
|
@@ -19,15 +19,20 @@ describe Rdayone::Journal do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "uses an entry finder" do
|
22
|
-
finder.should_receive(:
|
22
|
+
finder.should_receive(:find_entries)
|
23
23
|
subject
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
|
27
|
+
context "Rdayone::Finder interaction" do
|
28
|
+
subject { Rdayone::Journal.new("some_path") }
|
29
|
+
|
28
30
|
it "should default to the provided finder" do
|
29
|
-
|
30
|
-
|
31
|
+
expect(subject.finder).to be_instance_of(Rdayone::Finder)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "configures the provided finder with a path" do
|
35
|
+
expect(subject.finder.path).to eq("some_path")
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdayone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plist
|
@@ -67,6 +67,7 @@ extensions: []
|
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
69
|
- .gitignore
|
70
|
+
- .travis.yml
|
70
71
|
- Gemfile
|
71
72
|
- Guardfile
|
72
73
|
- LICENSE
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- lib/rdayone/version.rb
|
81
82
|
- rdayone.gemspec
|
82
83
|
- spec/fixtures/entries/02B82925942747709E1DF0518A650E1B.doentry
|
84
|
+
- spec/fixtures/photos/02B82925942747709E1DF0518A650E1B.jpg
|
83
85
|
- spec/rdayone/entry_list_spec.rb
|
84
86
|
- spec/rdayone/entry_spec.rb
|
85
87
|
- spec/rdayone/finder_spec.rb
|
@@ -99,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
101
|
version: '0'
|
100
102
|
segments:
|
101
103
|
- 0
|
102
|
-
hash:
|
104
|
+
hash: 281098409688963897
|
103
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
106
|
none: false
|
105
107
|
requirements:
|
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
version: '0'
|
109
111
|
segments:
|
110
112
|
- 0
|
111
|
-
hash:
|
113
|
+
hash: 281098409688963897
|
112
114
|
requirements: []
|
113
115
|
rubyforge_project:
|
114
116
|
rubygems_version: 1.8.23
|
@@ -117,6 +119,7 @@ specification_version: 3
|
|
117
119
|
summary: Access Day One journals from ruby.
|
118
120
|
test_files:
|
119
121
|
- spec/fixtures/entries/02B82925942747709E1DF0518A650E1B.doentry
|
122
|
+
- spec/fixtures/photos/02B82925942747709E1DF0518A650E1B.jpg
|
120
123
|
- spec/rdayone/entry_list_spec.rb
|
121
124
|
- spec/rdayone/entry_spec.rb
|
122
125
|
- spec/rdayone/finder_spec.rb
|