dayone_toolbox 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab3ddd4b806efe11802fb5f8e00843027c5210bd
4
- data.tar.gz: bdd491a5bda47915bb9efa49f29fe4874db1ec1f
3
+ metadata.gz: 493c6091664b059b0fb53aef9971221880b28939
4
+ data.tar.gz: 92a01c368f6fc9ddf81c58ede4718b0e3a25a84d
5
5
  SHA512:
6
- metadata.gz: f3fda84dd1dcbda0217772fb40d61a2830a74d1c092629c470daa5d35db1b9b38f327e73d51f368fabaaf1decfd8a77f54073b42dedf5950824e2af340f6716c
7
- data.tar.gz: ce56fc9c61888e5b0e39bdbe391a5c52e2ec4ee173710a962a6d691fd7ed417e01be494f1a54705bf4c082e020bb191b5a8ba853e47e7a9297e5b31ad0a7b0d7
6
+ metadata.gz: 392919afbf8fb2b38d90719d5e8fd06a6cad7fdd0d4a6636baf829bff51be8b23affe04896ecf87f65657f0332d4c02e593c57ac96dfdb03120d60192f869d68
7
+ data.tar.gz: bbf664b0e1a388a7dc55e4ffa96754cd2db4a3f76b30cbc589174b4e12a16cd9675aed0b92a432fc5db75844929e2d3575481202c077b4bd804ae2a1162b76cc
@@ -1,7 +1,11 @@
1
1
 
2
2
  module DayoneToolbox
3
+ EXPAND_PATH = File.expand_path('../../', __FILE__)
3
4
  end
4
5
 
6
+ require 'pathname'
7
+ require 'plist'
8
+
5
9
  require "dayone_toolbox/version"
6
10
  require "dayone_toolbox/journal"
7
11
  require "dayone_toolbox/entry"
@@ -1,6 +1,4 @@
1
1
 
2
- require 'plist'
3
-
4
2
  class DayoneToolbox::Entry
5
3
  KEY_TAGS = 'Tags'
6
4
  KEY_UUID = 'UUID'
@@ -28,10 +26,14 @@ class DayoneToolbox::Entry
28
26
  end
29
27
 
30
28
 
31
- attr_reader :file
29
+ attr_reader :file, :journal_dir
32
30
  def initialize(file)
33
- @file = file
34
- @hash = Plist.parse_xml(file)
31
+ @file = File.expand_path(file)
32
+ @journal_dir = nil
33
+ Pathname.new(file).ascend do |v|
34
+ @journal_dir = v.expand_path.to_s if v.basename.to_s.match('.dayone')
35
+ end
36
+ @hash = Plist.parse_xml(@file)
35
37
  end
36
38
 
37
39
 
@@ -81,6 +83,14 @@ class DayoneToolbox::Entry
81
83
  def weather=(attr) ; @hash[KEY_WEATHER] = attr ; end
82
84
  def weather? ; @hash.has_key?(KEY_WEATHER) ; end
83
85
 
86
+ def photo
87
+ jpg = File.join("#{@journal_dir}", "photos/#{uuid}.jpg")
88
+ File.exist?(jpg) ? jpg.to_s : nil
89
+ end
90
+
91
+ def photo?
92
+ photo ? true : false
93
+ end
84
94
 
85
95
  def custom_key(key)
86
96
  @hash[key]
@@ -3,14 +3,19 @@ class DayoneToolbox::Journal
3
3
  ENTRIES_DIR = 'entries/'
4
4
  PHOTOS_DIR = 'photos/'
5
5
 
6
- attr_reader :path, :entries_path, :photos_path
6
+ attr_reader :path, :expand_path, :entries_path, :photos_path
7
7
  def initialize(dir_path)
8
8
  @path = dir_path
9
- @entries_path = File.join(@path, ENTRIES_DIR)
10
- @photos_path = File.join(@path, PHOTOS_DIR)
9
+ @expand_path = File.expand_path(@path)
10
+ @entries_path = File.join(@expand_path, ENTRIES_DIR)
11
+ @photos_path = File.join(@expand_path, PHOTOS_DIR)
11
12
  end
12
13
 
13
14
  def entries
14
- Dir.glob("#{@entries_path}**/*.doentry")
15
+ Dir.glob("#{@entries_path}**/*.doentry", File::FNM_CASEFOLD)
16
+ end
17
+
18
+ def photos
19
+ Dir.glob("#{@photos_path}**/*.jpg", File::FNM_CASEFOLD)
15
20
  end
16
21
  end
@@ -1,3 +1,3 @@
1
1
  module DayoneToolbox
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dayone_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masato INOUE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-31 00:00:00.000000000 Z
11
+ date: 2017-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler