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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efda955abc597067d8f59fd3619e3569c244c54c
4
- data.tar.gz: cee080c393e0fe2bffc05d50375394f1f1eba5fc
3
+ metadata.gz: dc4f1d3dd3fe8a08c94ee2b3d2045d54908786ec
4
+ data.tar.gz: 8c772941d955ead4c437f182f4393f6e28cf6230
5
5
  SHA512:
6
- metadata.gz: 9fa15ef981a8d81bf2b4c4208c364777707bc5e66b7dcae65d80595c5942a01ee0a5d2905c5600a1e9d3e9f402811a21aad3807b973fc22f4239385c79a43998
7
- data.tar.gz: 56766d043547928e2722882d0cc89e943bddfa8e88df27d85b185700ce61f2fdffd575ba4792e30a3a5f6641f031ad37f11406a16c840178618f038afbbacda5
6
+ metadata.gz: f2c5b2526513ebb22363b73cbe17a56b3907e31386a95ba6838f38c840aac12f98fa102aec7cc2a9106e353842460e780d6501d53b084a44a39927a0935d7903
7
+ data.tar.gz: 7b2a8e855e3310bc7aeab0ffa8c570525ae8cff4b882da9c634a8c0a345fb5a9bdffa2ec03b94ce08d5b796321cfd9658808f42fe7e3bd67f84dc043369ab71c
data/exe/hasmenu CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'hasmenu'
3
+ require "hasmenu"
4
4
 
5
5
  trap "SIGINT" do
6
6
  puts "\nExecution interrupted. Exiting.".colorize(:yellow)
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
 
@@ -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
- file = YAML.load_file(path)
13
- File.open(path, "w") { |f| f.write file.to_yaml }
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 File.exist? path
43
+ unless valid_path? path
27
44
  print_invalid_path
28
45
  return
29
46
  end
30
47
 
31
48
  print_format_start
32
- if File.file?(path) && File.extname(path) == ".yml"
33
- format_file path
34
- elsif File.directory? path
35
- format_files path
36
- else
37
- print_invalid_path
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Hasmenu
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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.5
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-17 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor