wimdu 0.0.11

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3330da716906aba663f7d72fccb13e0ee30bfc4e
4
+ data.tar.gz: 8b65f93ee387f294130068d2bb54b4165eb2ad73
5
+ SHA512:
6
+ metadata.gz: bef19998d414f1a03e37cf51e6a90a9036155ce5ad9b38043f6090b2334cd2ab6a9e1522062dcea5f543ee0a4f40df68630cc0088f5b11d523fb3c562243a1fc
7
+ data.tar.gz: 3452c270358801bb9c2ae44cd4ce7f05d3f0deda3d148fce202bf4271f2c6dd5250f4033c23f81b987b76692ace3181c162f67afa571c5c999c037e608d5637c
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.semver ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 11
5
+ :special: ''
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wimdu.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Andrea Tore
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.
@@ -0,0 +1,91 @@
1
+ Z# Wimdu coding challenge
2
+
3
+ On wimdu.com, people can list their place to rent out. Wouldn't it be
4
+ great if there was a more nerdy way to enter your data? How about a
5
+ CLI?
6
+
7
+ ## The task
8
+
9
+ Build a standalone app that allows users to list their place via a
10
+ CLI. For the sake of simplicity, the data is kept locally. Similar to
11
+ the web app it should be possible to enter partial data and continue
12
+ later. However, make sure that in the end all required data is
13
+ present. Only when all data is present the newly created property
14
+ should appear in the list of all properties.
15
+
16
+ * Allow users to create new properties from the command line
17
+ * Prompt for attributes, validate the input
18
+ * When the data entry is interrupted, provide a way to resume entering data
19
+ * Store the property in some local storage; make sure no invalid data
20
+ is stored
21
+ * Every property has the following attributes
22
+ * title
23
+ * property type, which is one of
24
+ * holiday home
25
+ * apartment
26
+ * private room
27
+ * address
28
+ * nightly rate in EUR
29
+ * max guests
30
+ * email
31
+ * phone number
32
+
33
+ An example session could look like this:
34
+
35
+ $ wimdu list
36
+ No properties found.
37
+
38
+ $ wimdu new
39
+ Starting with new property ABC1DEF2.
40
+
41
+ Title: Amazing room at Wimdu Office
42
+ Address: ^C
43
+
44
+ $ wimdu list
45
+ No offers found.
46
+
47
+ $ wimdu continue ABC1DEF2
48
+ Continuing with ABC1DEF2
49
+
50
+ Address: Voltastr. 5, 13355 Berlin
51
+ Nightly rate in EUR: 12
52
+ Max guests: Two
53
+
54
+ Error: must be a number
55
+
56
+ Max guests: 2
57
+ ^C
58
+ $ wimdu continue ABC1DEF2
59
+ Continuing with ABC1DEF2
60
+
61
+ Email: foo@example.com
62
+ Phone number: +1 555 2368
63
+
64
+ Great job! Listing ABC1DEF2 is complete!
65
+
66
+ $ wimdu list
67
+ Found 1 offer.
68
+
69
+ ABC1DEF2: Amazing Room at Wimdu Office
70
+
71
+ ## Hints
72
+
73
+ It's totally fine to use 3rd party libraries like ruby's gems. You're
74
+ free to choose your storage mechanism/database. Just use the right
75
+ tool for the job.
76
+
77
+ It would be nice if you could send your results as a
78
+ repository. Either put it online or if you'd rather not have it be
79
+ public send it e.g. as a git bundle. Here's how to do that:
80
+
81
+ $ git bundle create jane-schmoe-wimdu-cli.bundle master
82
+
83
+ Just to check if stuff worked, you can clone from this file with
84
+
85
+ $ git clone -b master jane-schmoe-wimdu-cli.bundle
86
+
87
+ Mercurial also has a bundle feature. If you use any other version
88
+ control system we'd appreciate instructions on how to recreate the
89
+ repo.
90
+
91
+ Happy hacking!
@@ -0,0 +1,8 @@
1
+ require "rspec/core/rake_task"
2
+ require "bundler/gem_tasks"
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color', '--format documentation']
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'wimdu'
4
+
5
+ Wimdu::Cli::Utility.start(ARGV)
@@ -0,0 +1,18 @@
1
+ require "wimdu/version"
2
+ require "active_support/all"
3
+ require "active_model"
4
+ require 'forwardable'
5
+ require "pstore"
6
+ require "fileutils"
7
+ require "ap"
8
+
9
+
10
+ module Wimdu
11
+
12
+ require 'wimdu/property'
13
+ require 'wimdu/cli/utility'
14
+
15
+
16
+
17
+ # Your code goes here...
18
+ end
@@ -0,0 +1,54 @@
1
+ require 'thor'
2
+
3
+ module Wimdu
4
+ module Cli
5
+ class Utility < Thor
6
+
7
+ desc 'list', 'List properties'
8
+ def list
9
+ ap(Wimdu::Property.list)
10
+ end
11
+
12
+ desc 'new', 'New property'
13
+ def new
14
+ property = Wimdu::Property.new
15
+ ap("Starting with")
16
+ Wimdu::Property::ATTRIBUTES.each do |attribute|
17
+ begin
18
+ attribute_value = ask("Enter #{attribute.to_s.humanize.upcase}")
19
+ property.update_attribute(attribute, attribute_value)
20
+ rescue Wimdu::Property::InvalidPropertyError => validation_error
21
+ ap validation_error.message
22
+ retry
23
+ rescue Interrupt
24
+ ap("Exiting...") and exit
25
+ end
26
+ end
27
+ end
28
+
29
+ desc 'continue ID', 'Continue editing property ID'
30
+ def continue(id)
31
+ property = Wimdu::Property.find(id)
32
+ begin
33
+ Wimdu::Property.unsaved_attributes(property).each do |attribute|
34
+ begin
35
+ attribute_value = ask("Enter #{attribute.to_s.humanize.upcase}")
36
+ property.update_attribute(attribute, attribute_value)
37
+ rescue Wimdu::Property::InvalidPropertyError => validation_error
38
+ ap validation_error.message
39
+ retry
40
+ rescue Interrupt
41
+ ap("Exiting...") and exit
42
+ end
43
+ end
44
+ rescue Wimdu::Property::NothingToContinue => property_error
45
+ ap property_error.message and exit
46
+ end
47
+ end
48
+
49
+
50
+ end
51
+ end
52
+ end
53
+
54
+
@@ -0,0 +1,86 @@
1
+ module Wimdu
2
+ class Property
3
+ class InvalidPropertyError < StandardError; end;
4
+ class NothingToContinue < StandardError; end;
5
+
6
+ include ActiveModel::Model
7
+ include ActiveModel::Validations
8
+
9
+ attr_reader :_id
10
+
11
+ ATTRIBUTES = [:title, :property_type, :nightly_rate, :max_guests, :email, :phone_number]
12
+ ATTRIBUTES.each{|attribute| attr_accessor attribute}
13
+
14
+ validates_length_of :title, within: 6..20, allow_nil: true
15
+ validates_inclusion_of :property_type, in: %w( holiday_home apartment private_room address ), allow_nil: true
16
+ validates_numericality_of :nightly_rate, allow_nil: true
17
+ validates_numericality_of :max_guests, only_integer: true, allow_nil: true
18
+ validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i}, allow_nil: true
19
+ validates_length_of :phone_number, within: 6..20, allow_nil: true
20
+
21
+
22
+ extend Forwardable
23
+
24
+ def initialize
25
+ @_id = SecureRandom.hex(5)
26
+ end
27
+
28
+ def_delegator Wimdu::Property, :transaction
29
+ def_delegator Wimdu::Property, :connection
30
+
31
+
32
+ def update_attribute(attribute, value)
33
+ self.send("#{attribute}=", value)
34
+ self.save
35
+ end
36
+
37
+ def save
38
+ raise InvalidPropertyError, errors.full_messages.join unless valid?
39
+ transaction{connection[@_id] = self}
40
+ end
41
+
42
+ def delete(key)
43
+ transaction{connection.delete(key)}
44
+ end
45
+
46
+ class << self
47
+
48
+ def connection
49
+ @connection ||= PStore.new('wimdu.db')
50
+ end
51
+
52
+ def transaction
53
+ connection.transaction do
54
+ yield
55
+ end
56
+ end
57
+
58
+ def delete_all
59
+ transaction do
60
+ connection.roots.each do |key|
61
+ connection.delete(key)
62
+ end
63
+ end
64
+ end
65
+
66
+ def list
67
+ transaction{connection.roots.map{|id| connection[id]}.map{|property| property._id}}
68
+ end
69
+
70
+ def find(id)
71
+ transaction{connection[id]}
72
+ end
73
+
74
+ def unsaved_attributes(property)
75
+ last_attribute = Wimdu::Property::ATTRIBUTES.find{|attribute| property.send(attribute).nil?} or raise NothingToContinue, "Property already saved"
76
+ Wimdu::Property::ATTRIBUTES[Wimdu::Property::ATTRIBUTES.index(last_attribute)..-1]
77
+ end
78
+
79
+ end
80
+
81
+
82
+
83
+ end
84
+
85
+
86
+ end
@@ -0,0 +1,20 @@
1
+ module Wimdu
2
+ def self.load_version
3
+ s = ''
4
+ open(File.expand_path('../../../.semver', __FILE__), 'r') do |f|
5
+ v = Hash[f.readlines.map{ |line|
6
+ line
7
+ }.select{ |line|
8
+ line =~ /^:.*:/
9
+ }.map{ |spec|
10
+ spec.split(':').map{ |w| w.strip }.reject { |w| w.empty? }
11
+ }]
12
+ s = "#{v['major']}.#{v['minor']}.#{v['patch']}#{v['special'].chop.reverse.chop.reverse}"
13
+ end
14
+ s
15
+ end
16
+
17
+ VERSION ||= load_version
18
+
19
+
20
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Wimdu::Property do
4
+ context "Raise validation error on" do
5
+
6
+ it 'INVALID CONTENT TYPE' do
7
+
8
+ end
9
+
10
+ it 'INVALID DESCRIPTION' do
11
+
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'wimdu'
2
+
3
+ RSpec.configure do |config|
4
+
5
+ end
6
+
7
+
8
+
9
+
10
+
11
+
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wimdu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wimdu"
8
+ spec.version = Wimdu::VERSION
9
+ spec.authors = ["Andrea Tore"]
10
+ spec.email = ["tore.andrea@gmail.com"]
11
+ spec.summary = %q{Wimdu Properties CLI}
12
+ spec.description = %q{Wimdu Properties CLI Utility}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['wimdu']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '~> 2.1'
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake", "10.4.2"
24
+ spec.add_development_dependency "semver", "1.0.1"
25
+ spec.add_development_dependency "rspec", "3.2.0"
26
+ spec.add_development_dependency "pry", "0.10.1"
27
+ spec.add_runtime_dependency "thor", "0.19.1"
28
+ spec.add_runtime_dependency "activesupport", "4.2.1"
29
+ spec.add_runtime_dependency "activemodel", "4.2.1"
30
+ spec.add_runtime_dependency "parallel", "1.3.4"
31
+ spec.add_runtime_dependency "awesome_print", "1.6.1"
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wimdu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
+ platform: ruby
6
+ authors:
7
+ - Andrea Tore
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: semver
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.10.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.10.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.19.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.19.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 4.2.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 4.2.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: activemodel
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 4.2.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 4.2.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: parallel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.3.4
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.4
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.6.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.6.1
153
+ description: Wimdu Properties CLI Utility
154
+ email:
155
+ - tore.andrea@gmail.com
156
+ executables:
157
+ - wimdu
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".semver"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/wimdu
168
+ - lib/wimdu.rb
169
+ - lib/wimdu/cli/utility.rb
170
+ - lib/wimdu/property.rb
171
+ - lib/wimdu/version.rb
172
+ - spec/property_spec.rb
173
+ - spec/spec_helper.rb
174
+ - wimdu.gemspec
175
+ homepage: ''
176
+ licenses:
177
+ - MIT
178
+ metadata: {}
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.1'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubyforge_project:
195
+ rubygems_version: 2.4.4
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: Wimdu Properties CLI
199
+ test_files:
200
+ - spec/property_spec.rb
201
+ - spec/spec_helper.rb