itinerary 0.1 → 0.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjBmNTg1NjNhMTkzNDVmODJhZDBmYTJmODI0YzNmN2E1ZmI2ODdmYg==
4
+ YmNlNWMxYmI4MzhiMTdjZmU5ZjU0YzBhZDlhY2MyNTgyMTcwMmZiYQ==
5
5
  data.tar.gz: !binary |-
6
- M2EwMTEzMzUwNTk0NWJlOTQ3OTI5NDRhZGNlYzhmOWFkZDExMWUzZg==
6
+ Nzk2YmZmODFhM2M3NjhiZDYzMGE3ZDQ5MjczMzUwOTc1NzJkODllOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YmI4OTFmYWI0MzYwMDE0NTg0MjEyMWEyZTk1M2EzODlkNjY3YmQ5MzZlMzlj
10
- MDA4Y2U2ZDJlNWU0Yjc5NDk3NTUzMDE3N2YzMWY1ZWFjZjliN2EyYjJkMDk4
11
- Nzg2MTI0YWQyYWUzODM2NmFjZWY3MmFlNzZjYTYyMGE0MmEzZmY=
9
+ ZTMzY2NkMjM5MjQ3MmExYzBiMzFkM2RkNjM0MDBlZTIxMTQxMmRkMTZmNTUx
10
+ OTNlMDc0MDE1NGEyODBkNjI3YzIyNWViYTRlNjYxNzNmOGVhYTdiZTY3ZTUw
11
+ ZWQ2NWI4ZDgwMTNkNmVjZTIwMzQzOWMwMjBmNDZmMGMyYjNiOTM=
12
12
  data.tar.gz: !binary |-
13
- MDQ2MTM2ZTU3NjEwMDNiOTUyMmU2NWM4YmJlMDhlNDRkMDE0MDhjMGE1MTNi
14
- MzAyYjBkYjcxZWI5MjkwN2ViYTEwZjkzNWZkZTBlZDFjNmY5ODFjZjNlNTE4
15
- NTA1YmVmZTRhN2QzZGUyMjJhNjMyNzJmYmRlMTRhNTZmNGM1NjY=
13
+ ODVhYjgwMzIyYzY2ZTI2ZDEyNTllNzZjNWI1MTkzYzgyYWMwNDI5MTI0ZmJi
14
+ MWEyZGJjZWE0NWM1NjdjYTEzMzBmZWU2NTI2N2RjZTBiNjU4MDE5MDMxOTAw
15
+ MGYwMTFjZDgxZGJmYTkzOTE4Y2Q4MTk4ODZhNDc4MjA0ZGZkY2M=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .geocoding-cache
@@ -6,6 +6,8 @@ require 'itinerary/tool'
6
6
 
7
7
  require 'itinerary/tools/convert'
8
8
  require 'itinerary/tools/create'
9
+ require 'itinerary/tools/diff'
10
+ require 'itinerary/tools/edit'
9
11
  require 'itinerary/tools/find-dups'
10
12
  require 'itinerary/tools/import'
11
13
  require 'itinerary/tools/list'
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency 'rake'
23
23
 
24
24
  gem.add_runtime_dependency 'builder'
25
- gem.add_runtime_dependency 'daybreak', '0.2.4'
25
+ gem.add_runtime_dependency 'daybreak'
26
26
  gem.add_runtime_dependency 'faraday'
27
27
  gem.add_runtime_dependency 'faraday_middleware'
28
28
  gem.add_runtime_dependency 'geocoder'
@@ -28,7 +28,7 @@ class Itinerary
28
28
  @name = options[:name]
29
29
  @root = options[:root] or raise "Must specify root"
30
30
  @root = Pathname.new(@root).expand_path
31
- @geocoding_cache_path = options[:geocoding_cache] || '.geocoding-cache'
31
+ @geocoding_cache_path = @root + (options[:geocoding_cache] || '.geocoding-cache')
32
32
  setup_geocoding_cache
33
33
  @entries = []
34
34
  read_entries
@@ -125,8 +125,15 @@ class Itinerary
125
125
  when :radius
126
126
  # ignored here -- used above
127
127
  when :flags
128
+ matched.reject! do |rec|
129
+ value.find do |f, v|
130
+ rec.method("#{f}?").call != v
131
+ end
132
+ end
133
+ when :entries
134
+ values = value.split(',').map { |v| v[0] == '/' ? Pathname.new(v) : v }
128
135
  matched.select! do |rec|
129
- value.find { |v| rec.method("#{v}?").call }
136
+ values.find { |v| rec.match(v, self) }
130
137
  end
131
138
  else
132
139
  raise "Unknown field: #{key.inspect}" unless Record.field(key) || Record.instance_methods.include?(key)
@@ -149,8 +156,16 @@ class Itinerary
149
156
  matches
150
157
  end
151
158
 
152
- def [](path)
153
- @entries.find { |r| r.path == path }
159
+ def find(query)
160
+ @entries.find { |r| r.match(query, self) }
161
+ end
162
+
163
+ def select(query)
164
+ @entries.select { |r| r.match(query, self) }
165
+ end
166
+
167
+ def [](query)
168
+ find(query)
154
169
  end
155
170
 
156
171
  def parse_params(params)
@@ -163,7 +178,12 @@ class Itinerary
163
178
  when :radius
164
179
  filters.radius = value.to_f
165
180
  when :flags
166
- filters.flags = value.split(',').map { |f| f.to_sym }
181
+ filters.flags = Hash[
182
+ value.split(',').map do |v|
183
+ v =~ /^(!?)(\w+)$/ or raise "Invalid flag specification: #{v.inspect}"
184
+ [$2.to_sym, ($1 != '!')]
185
+ end
186
+ ]
167
187
  when :show_fields
168
188
  options.show_fields = value.split(',').map { |f| f.to_sym }
169
189
  when :hide_fields
@@ -159,11 +159,31 @@ class Itinerary
159
159
  end
160
160
 
161
161
  def visited?
162
- visited && visited < DateTime.now
162
+ !visited.nil? && visited < DateTime.now
163
163
  end
164
164
 
165
165
  def to_visit?
166
- visited && visited >= DateTime.now
166
+ !visited.nil? && visited >= DateTime.now
167
+ end
168
+
169
+ def contacted?
170
+ !contacted.nil?
171
+ end
172
+
173
+ def declined?
174
+ !declined.nil?
175
+ end
176
+
177
+ def match(query, itinerary)
178
+ case query
179
+ when Pathname
180
+ query == path
181
+ when String
182
+ rpath = path.relative_path_from(itinerary.entries_path).to_s
183
+ File.fnmatch(query, rpath)
184
+ else
185
+ raise "Don't know how to query on #{query.inspect}"
186
+ end
167
187
  end
168
188
 
169
189
  def string_to_key(str)
@@ -181,16 +201,7 @@ class Itinerary
181
201
  path += string_to_key(country) if country
182
202
  path += string_to_key(state) if state
183
203
  raise "Can't make key from empty name" unless name
184
- key = string_to_key(name)
185
- i = 1
186
- p = nil
187
- loop do
188
- p = key.dup
189
- p += i.to_s if i > 1
190
- break unless (path + p).exist?
191
- i += 1
192
- end
193
- path += p
204
+ path += string_to_key(name)
194
205
  path
195
206
  end
196
207
 
@@ -213,17 +224,18 @@ class Itinerary
213
224
 
214
225
  def to_text(options={})
215
226
  t = StringIO.new
216
- field_keys = options[:field_keys] || @@fields.keys
217
- field_keys.map { |k| @@fields[k] }.each do |field|
218
- next if field.key == :notes
219
- value = self[field.key] or next
227
+ keys = options[:field_keys] || @@fields.keys
228
+ keys.each do |key|
229
+ next if key == :notes
230
+ value = self[key] or next
220
231
  if value =~ /\n/
221
232
  value = "\n" + value.gsub(/^/, "\t")
222
233
  end
223
- t.puts "%-#{MaxFieldNameLength + 1}.#{MaxFieldNameLength + 1}s %s" % [field.name + ':', value]
234
+ field = @@fields[key]
235
+ t.puts "%-#{MaxFieldNameLength + 1}.#{MaxFieldNameLength + 1}s %s" % [(field ? field.name : key.to_s.capitalize) + ':', value]
224
236
  end
225
237
  t.puts
226
- t.puts notes if notes && field_keys.include?(:notes)
238
+ t.puts notes if notes && keys.include?(:notes)
227
239
  t.rewind
228
240
  t.read
229
241
  end
@@ -316,16 +328,21 @@ class Itinerary
316
328
  end
317
329
 
318
330
  def print_diff(other)
319
- (self.keys + other.keys).sort.uniq.each do |key|
320
- if self[key] != other[key]
321
- puts "\t" + "#{key}:"
322
- if self[key] && !other[key]
323
- puts "\t\t" + "- #{self[key].inspect}"
324
- elsif !self[key] && other[key]
325
- puts "\t\t" + "+ #{other[key].inspect}"
326
- elsif self[key] != other[key]
327
- puts "\t\t" + "< #{self[key].inspect}"
328
- puts "\t\t" + "> #{other[key].inspect}"
331
+ if self != other
332
+ puts
333
+ puts "< #{self.path}"
334
+ puts "> #{other.path}"
335
+ (self.keys + other.keys).sort.uniq.each do |key|
336
+ if self[key] != other[key]
337
+ puts "\t" + "#{key}:"
338
+ if self[key] && !other[key]
339
+ puts "\t\t" + "- #{self[key].inspect}"
340
+ elsif !self[key] && other[key]
341
+ puts "\t\t" + "+ #{other[key].inspect}"
342
+ elsif self[key] != other[key]
343
+ puts "\t\t" + "< #{self[key].inspect}"
344
+ puts "\t\t" + "> #{other[key].inspect}"
345
+ end
329
346
  end
330
347
  end
331
348
  end
@@ -0,0 +1,18 @@
1
+ class Itinerary
2
+ class DiffTool < Tool
3
+
4
+ def self.name
5
+ 'diff'
6
+ end
7
+
8
+ def parse(args)
9
+ @recs = args.map { |id| @itinerary[id] or raise "No record with id #{id.inspect}" }
10
+ raise "Can only diff two records" if @recs.length != 2
11
+ end
12
+
13
+ def run
14
+ @recs[0].print_diff(@recs[1])
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ class Itinerary
2
+ class EditTool < Tool
3
+
4
+ def self.name
5
+ 'edit'
6
+ end
7
+
8
+ def parse(args)
9
+ @recs = args.map { |id| @itinerary[id] or raise "No record with id #{id.inspect}" }
10
+ end
11
+
12
+ def run
13
+ @recs.each do |rec|
14
+ old_rec = rec.dup
15
+ rec.edit(:wait => true)
16
+ rec = Record.load(rec.path)
17
+ if rec == old_rec
18
+ warn "Unchanged"
19
+ next
20
+ end
21
+ unless rec.geocoded?
22
+ rec.geocode or raise "Failed to geocode #{rec.address.inspect} (entry left in #{rec.path})"
23
+ rec.save!
24
+ end
25
+ old_rec.print_diff(rec)
26
+ new_path = rec.make_path(@itinerary.entries_path)
27
+ if new_path != rec.path
28
+ old_path = rec.path
29
+ rec.path.rename(new_path)
30
+ rec.path = new_path
31
+ warn "Renamed #{old_path} to #{new_path}"
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -7,29 +7,28 @@ class Itinerary
7
7
 
8
8
  def parse(args)
9
9
  @view_class = View::Text
10
+ @params = {}
10
11
  while args.first =~ /^-(\w+)$/
11
12
  args.shift
12
- @view_class = case $1
13
+ case $1
13
14
  when 't'
14
- View::Tab
15
+ @view_class = View::Tab
15
16
  when 'h'
16
- View::HTML
17
+ @view_class = View::HTML
17
18
  when 'k'
18
- View::KML
19
+ @view_class = View::KML
20
+ when 'f'
21
+ key, value = args.shift.split('=', 2)
22
+ @params[key] = value
19
23
  end
20
24
  end
21
- params = Hash[
22
- args.map do |arg|
23
- key, value = *arg.split('=', 2)
24
- [key.to_sym, value]
25
- end
26
- ]
27
- @filters, @options = @itinerary.parse_params(params)
25
+ @params[:entries] = args.join(',') unless args.empty?
28
26
  end
29
27
 
30
28
  def run
31
- view = @view_class.new(@itinerary, @options)
32
- print view.render(@itinerary.entries(@filters))
29
+ filters, options = @itinerary.parse_params(@params)
30
+ view = @view_class.new(@itinerary, options)
31
+ print view.render(@itinerary.entries(filters))
33
32
  end
34
33
 
35
34
  end
@@ -1,5 +1,5 @@
1
1
  class Itinerary
2
2
 
3
- VERSION = '0.1'
3
+ VERSION = '0.4'
4
4
 
5
5
  end
@@ -3,7 +3,7 @@ class Itinerary
3
3
  class Text < View
4
4
 
5
5
  def render_record(rec)
6
- @output.puts "[#{rec.path}]"
6
+ @output.puts "[#{rec.path.relative_path_from(@itinerary.entries_path)}]"
7
7
  @output.puts rec.to_text(:field_keys => @field_keys)
8
8
  end
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itinerary
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Labovitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-02 00:00:00.000000000 Z
11
+ date: 2013-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: daybreak
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.4
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.4
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: faraday
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +187,8 @@ files:
187
187
  - lib/itinerary/tool.rb
188
188
  - lib/itinerary/tools/convert.rb
189
189
  - lib/itinerary/tools/create.rb
190
+ - lib/itinerary/tools/diff.rb
191
+ - lib/itinerary/tools/edit.rb
190
192
  - lib/itinerary/tools/find-dups.rb
191
193
  - lib/itinerary/tools/import.rb
192
194
  - lib/itinerary/tools/list.rb
@@ -216,7 +218,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
218
  version: '0'
217
219
  requirements: []
218
220
  rubyforge_project:
219
- rubygems_version: 2.0.0
221
+ rubygems_version: 2.0.3
220
222
  signing_key:
221
223
  specification_version: 4
222
224
  summary: Keep track of travel itineraries