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 ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Rdayone is a simple Ruby library for accessing Day One journals.
4
4
 
5
+ [![Build Status](https://secure.travis-ci.org/simonjefford/rdayone.png)](http://travis-ci.org/simonjefford/rdayone)
6
+
7
+
5
8
  ## Installation
6
9
 
7
10
  Add this line to your application's Gemfile:
data/lib/rdayone/entry.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  module Rdayone
2
2
  class Entry
3
- def initialize(plist_hash = {})
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",
@@ -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
- entry = Rdayone::Entry.new(Plist::parse_xml(@entry_paths[index]))
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
@@ -1,7 +1,21 @@
1
1
  module Rdayone
2
2
  class Finder
3
- def self.find(path)
4
- EntryList.new(Dir["#{path}/entries/*.doentry"])
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
@@ -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.find(file_path)
8
+ @entries = finder.find_entries
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module Rdayone
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,7 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rdayone::EntryList do
4
- subject { Rdayone::EntryList.new(entry_fixture_paths) }
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
@@ -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
@@ -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 = Rdayone::Finder.find('spec/fixtures')
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
- describe "loading" do
4
+ context "loading" do
5
5
  let(:finder) do
6
6
  f = double("finder")
7
- f.stub(:find) { [double("entry")] }
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(:find).with("some_path")
22
+ finder.should_receive(:find_entries)
23
23
  subject
24
24
  end
25
25
  end
26
26
 
27
- describe "finder interaction" do
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
- journal = Rdayone::Journal.new("some_path")
30
- expect(journal.finder).to eq(Rdayone::Finder)
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
@@ -5,6 +5,6 @@ def entry_fixture_paths
5
5
  Dir['spec/fixtures/entries/*']
6
6
  end
7
7
 
8
- def photo_fixture_paths
9
- Dir['spec/fixtures/photos/*']
8
+ def photo_fixture_path_for_uuid(uuid)
9
+ File.expand_path("spec/fixtures/photos/#{uuid}.jpg")
10
10
  end
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.1
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-17 00:00:00.000000000 Z
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: 4021303384569122307
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: 4021303384569122307
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