rdayone 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/Guardfile +7 -0
- data/LICENSE +22 -0
- data/README.md +38 -0
- data/Rakefile +2 -0
- data/lib/rdayone/entry.rb +21 -0
- data/lib/rdayone/entry_list.rb +30 -0
- data/lib/rdayone/finder.rb +7 -0
- data/lib/rdayone/journal.rb +11 -0
- data/lib/rdayone/version.rb +3 -0
- data/lib/rdayone.rb +9 -0
- data/rdayone.gemspec +20 -0
- data/spec/fixtures/entries/02B82925942747709E1DF0518A650E1B.doentry +42 -0
- data/spec/rdayone/entry_list_spec.rb +42 -0
- data/spec/rdayone/entry_spec.rb +32 -0
- data/spec/rdayone/finder_spec.rb +8 -0
- data/spec/rdayone/journal_spec.rb +33 -0
- data/spec/spec_helper.rb +10 -0
- metadata +124 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Simon Jefford
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Rdayone
|
2
|
+
|
3
|
+
Rdayone is a simple Ruby library for accessing Day One journals.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rdayone'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rdayone
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
require "rdayone"
|
23
|
+
journal = Rdayone::Journal.new("/path/to/Journal.dayone")
|
24
|
+
journal.entries # An Enumerable array like object that contains all your entries
|
25
|
+
```
|
26
|
+
|
27
|
+
## NOTE
|
28
|
+
|
29
|
+
This is a *very* early release. Entries currently contain the entry text
|
30
|
+
and date only.
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rdayone
|
2
|
+
class Entry
|
3
|
+
def initialize(plist_hash = {})
|
4
|
+
@plist_hash = plist_hash
|
5
|
+
@attribute_mappings = {
|
6
|
+
text: "Entry Text",
|
7
|
+
creation_date: "Creation Date",
|
8
|
+
identifier: "UUID"
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method, *args)
|
13
|
+
key = @attribute_mappings[method]
|
14
|
+
if key
|
15
|
+
@plist_hash[key]
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'plist'
|
2
|
+
|
3
|
+
module Rdayone
|
4
|
+
class EntryList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(entry_paths)
|
8
|
+
@entry_paths = entry_paths
|
9
|
+
@entry_cache = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch(index)
|
13
|
+
raise ArgumentError if index > @entry_paths.length
|
14
|
+
entry = @entry_cache[index]
|
15
|
+
unless entry
|
16
|
+
entry = Rdayone::Entry.new(Plist::parse_xml(@entry_paths[index]))
|
17
|
+
@entry_cache[index] = entry
|
18
|
+
end
|
19
|
+
entry
|
20
|
+
end
|
21
|
+
|
22
|
+
alias :[] :fetch
|
23
|
+
|
24
|
+
def each
|
25
|
+
(0..@entry_paths.length - 1).each do |index|
|
26
|
+
yield self.fetch(index)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/rdayone.rb
ADDED
data/rdayone.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rdayone/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Simon Jefford"]
|
6
|
+
gem.email = ["simon.jefford@gmail.com"]
|
7
|
+
gem.description = %q{A ruby gem for accessing Day One (http://dayoneapp.com/) journals}
|
8
|
+
gem.summary = %q{Access Day One journals from ruby.}
|
9
|
+
gem.homepage = "http://github.com/simonjefford/rdayone"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "rdayone"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Rdayone::VERSION
|
17
|
+
gem.add_dependency('plist', '~> 3.1.0')
|
18
|
+
gem.add_development_dependency('rake')
|
19
|
+
gem.add_development_dependency('rspec', '~> 2.11.0')
|
20
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>Creation Date</key>
|
6
|
+
<date>2012-08-07T08:44:32Z</date>
|
7
|
+
<key>Entry Text</key>
|
8
|
+
<string>Something cool happened in London</string>
|
9
|
+
<key>Location</key>
|
10
|
+
<dict>
|
11
|
+
<key>Administrative Area</key>
|
12
|
+
<string>England</string>
|
13
|
+
<key>Country</key>
|
14
|
+
<string>United Kingdom</string>
|
15
|
+
<key>Latitude</key>
|
16
|
+
<real>51.505845000000001</real>
|
17
|
+
<key>Locality</key>
|
18
|
+
<string>London</string>
|
19
|
+
<key>Longitude</key>
|
20
|
+
<real>-0.1308377</real>
|
21
|
+
<key>Place Name</key>
|
22
|
+
<string>The Mall</string>
|
23
|
+
<key>State</key>
|
24
|
+
<string>manual</string>
|
25
|
+
</dict>
|
26
|
+
<key>Starred</key>
|
27
|
+
<false/>
|
28
|
+
<key>UUID</key>
|
29
|
+
<string>02B82925942747709E1DF0518A650E1B</string>
|
30
|
+
<key>Weather</key>
|
31
|
+
<dict>
|
32
|
+
<key>Celsius</key>
|
33
|
+
<string>15</string>
|
34
|
+
<key>Description</key>
|
35
|
+
<string>Partly Cloudy</string>
|
36
|
+
<key>Fahrenheit</key>
|
37
|
+
<string>59</string>
|
38
|
+
<key>IconName</key>
|
39
|
+
<string>pcloudy.png</string>
|
40
|
+
</dict>
|
41
|
+
</dict>
|
42
|
+
</plist>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdayone::EntryList do
|
4
|
+
subject { Rdayone::EntryList.new(entry_fixture_paths) }
|
5
|
+
|
6
|
+
context "entry fetching" do
|
7
|
+
it "returns the nth entry when used like an array" do
|
8
|
+
e = subject[0]
|
9
|
+
expect(e).to_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a populated Entry" do
|
13
|
+
e = subject[0]
|
14
|
+
expect(e.text).to eq("Something cool happened in London")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "throws an error if the index is out of range" do
|
18
|
+
expect { subject[100] }.to raise_error(ArgumentError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "enumerating" do
|
23
|
+
it "implements each" do
|
24
|
+
entries = []
|
25
|
+
subject.each { |e| entries << e }
|
26
|
+
expect(entries.count).to eq(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "is Enumerable" do
|
30
|
+
mapresult = subject.map { |e| e.text }
|
31
|
+
expect(mapresult).to eq(["Something cool happened in London"])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "caching" do
|
36
|
+
it "should cache entries for subsequent requests" do
|
37
|
+
list = subject.to_a
|
38
|
+
Plist.stub(:parse_xml).and_raise("Entry was not cached")
|
39
|
+
subject[0]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdayone::Entry do
|
4
|
+
context "initialisation" do
|
5
|
+
it "can occur with no arguments" do
|
6
|
+
entry = Rdayone::Entry.new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "basic parsing" do
|
11
|
+
let(:creation_date) { DateTime.new }
|
12
|
+
|
13
|
+
subject do
|
14
|
+
hash = { "Creation Date" => creation_date,
|
15
|
+
"Entry Text" => "something cool happened today",
|
16
|
+
"UUID" => "02B82925942747709E1DF0518A650E1B"}
|
17
|
+
Rdayone::Entry.new(hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "populates the identifier" do
|
21
|
+
expect(subject.identifier).to eq("02B82925942747709E1DF0518A650E1B")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "populates the entry text" do
|
25
|
+
expect(subject.text).to eq("something cool happened today")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "populates the creation date" do
|
29
|
+
expect(subject.creation_date).to eq(creation_date)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Rdayone::Journal do
|
4
|
+
describe "loading" do
|
5
|
+
let(:finder) do
|
6
|
+
f = double("finder")
|
7
|
+
f.stub(:find) { [double("entry")] }
|
8
|
+
f
|
9
|
+
end
|
10
|
+
|
11
|
+
subject { Rdayone::Journal.new("some_path", finder) }
|
12
|
+
|
13
|
+
it "takes a file path" do
|
14
|
+
expect(subject.file_path).to eq("some_path")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "populates an entries list" do
|
18
|
+
expect(subject.entries.count).to eq(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "uses an entry finder" do
|
22
|
+
finder.should_receive(:find).with("some_path")
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "finder interaction" do
|
28
|
+
it "should default to the provided finder" do
|
29
|
+
journal = Rdayone::Journal.new("some_path")
|
30
|
+
expect(journal.finder).to eq(Rdayone::Finder)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rdayone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Simon Jefford
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: plist
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.11.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.0
|
62
|
+
description: A ruby gem for accessing Day One (http://dayoneapp.com/) journals
|
63
|
+
email:
|
64
|
+
- simon.jefford@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Guardfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/rdayone.rb
|
76
|
+
- lib/rdayone/entry.rb
|
77
|
+
- lib/rdayone/entry_list.rb
|
78
|
+
- lib/rdayone/finder.rb
|
79
|
+
- lib/rdayone/journal.rb
|
80
|
+
- lib/rdayone/version.rb
|
81
|
+
- rdayone.gemspec
|
82
|
+
- spec/fixtures/entries/02B82925942747709E1DF0518A650E1B.doentry
|
83
|
+
- spec/rdayone/entry_list_spec.rb
|
84
|
+
- spec/rdayone/entry_spec.rb
|
85
|
+
- spec/rdayone/finder_spec.rb
|
86
|
+
- spec/rdayone/journal_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: http://github.com/simonjefford/rdayone
|
89
|
+
licenses: []
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
hash: 4021303384569122307
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 4021303384569122307
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.23
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Access Day One journals from ruby.
|
118
|
+
test_files:
|
119
|
+
- spec/fixtures/entries/02B82925942747709E1DF0518A650E1B.doentry
|
120
|
+
- spec/rdayone/entry_list_spec.rb
|
121
|
+
- spec/rdayone/entry_spec.rb
|
122
|
+
- spec/rdayone/finder_spec.rb
|
123
|
+
- spec/rdayone/journal_spec.rb
|
124
|
+
- spec/spec_helper.rb
|