hasmenu 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/hasmenu +1 -1
- data/lib/hasmenu.rb +3 -3
- data/lib/hasmenu/formatter.rb +32 -10
- data/lib/hasmenu/printer.rb +4 -0
- data/lib/hasmenu/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc4f1d3dd3fe8a08c94ee2b3d2045d54908786ec
|
4
|
+
data.tar.gz: 8c772941d955ead4c437f182f4393f6e28cf6230
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2c5b2526513ebb22363b73cbe17a56b3907e31386a95ba6838f38c840aac12f98fa102aec7cc2a9106e353842460e780d6501d53b084a44a39927a0935d7903
|
7
|
+
data.tar.gz: 7b2a8e855e3310bc7aeab0ffa8c570525ae8cff4b882da9c634a8c0a345fb5a9bdffa2ec03b94ce08d5b796321cfd9658808f42fe7e3bd67f84dc043369ab71c
|
data/exe/hasmenu
CHANGED
data/lib/hasmenu.rb
CHANGED
@@ -16,10 +16,10 @@ module Hasmenu
|
|
16
16
|
puts Hasmenu::VERSION
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "format <path>", "Format Has.Menu data"
|
19
|
+
desc "format <type> <path>", "Format Has.Menu data"
|
20
20
|
option :location, aliases: :l, desc: "Path to data repository"
|
21
|
-
def format(path)
|
22
|
-
Hasmenu::Formatter.new(options).format(path)
|
21
|
+
def format(type, path)
|
22
|
+
Hasmenu::Formatter.new(type, options).format(path)
|
23
23
|
end
|
24
24
|
map "f" => :format
|
25
25
|
|
data/lib/hasmenu/formatter.rb
CHANGED
@@ -4,13 +4,30 @@ module Hasmenu
|
|
4
4
|
class Formatter
|
5
5
|
include Printer
|
6
6
|
|
7
|
-
def initialize(options)
|
7
|
+
def initialize(type, options)
|
8
|
+
@type = type
|
8
9
|
@location = options[:location] || Dir.pwd
|
9
10
|
end
|
10
11
|
|
12
|
+
def valid_path?(path)
|
13
|
+
(File.file?(path) && File.extname(path) == ".yml") || File.directory?(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_list(path)
|
17
|
+
data = YAML.load_file(path)
|
18
|
+
unless data.is_a? Array
|
19
|
+
print_invalid_path
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
data.sort_by! { |e| [e["chain"], e["uid"]] }
|
24
|
+
File.open(path, "w") { |f| f.write data.to_yaml }
|
25
|
+
print_format_for File.basename(path)
|
26
|
+
end
|
27
|
+
|
11
28
|
def format_file(path)
|
12
|
-
|
13
|
-
File.open(path, "w") { |f| f.write
|
29
|
+
data = YAML.load_file(path)
|
30
|
+
File.open(path, "w") { |f| f.write data.to_yaml }
|
14
31
|
print_format_for File.basename(File.dirname(path))
|
15
32
|
end
|
16
33
|
|
@@ -23,18 +40,23 @@ module Hasmenu
|
|
23
40
|
def format(path)
|
24
41
|
path = File.join(@location, path)
|
25
42
|
|
26
|
-
unless
|
43
|
+
unless valid_path? path
|
27
44
|
print_invalid_path
|
28
45
|
return
|
29
46
|
end
|
30
47
|
|
31
48
|
print_format_start
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
49
|
+
case @type
|
50
|
+
when "chains", "restaurants"
|
51
|
+
format_list path
|
52
|
+
when "menu"
|
53
|
+
if File.directory? path
|
54
|
+
format_files path
|
55
|
+
else
|
56
|
+
format_file path
|
57
|
+
end
|
58
|
+
else
|
59
|
+
print_invalid_format
|
38
60
|
end
|
39
61
|
end
|
40
62
|
end
|
data/lib/hasmenu/printer.rb
CHANGED
@@ -12,6 +12,10 @@ module Hasmenu
|
|
12
12
|
puts "\n error: please provide a valid file or directory\n".colorize(:red)
|
13
13
|
end
|
14
14
|
|
15
|
+
def print_invalid_format
|
16
|
+
puts "\n error: please provide a valid format type\n".colorize(:red)
|
17
|
+
end
|
18
|
+
|
15
19
|
def print_format_start
|
16
20
|
puts "formatting files".colorize(:green)
|
17
21
|
end
|
data/lib/hasmenu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hasmenu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geordee Naliyath
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|