cheatly 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzFkNTI0M2EyMTY4YjYyMmJlODlmZTQ3ZGY4Y2U4YzI4YjA5Mzg1MA==
4
+ ODM2NTY4NjI1YjY0ZGY0MGQwNzAyOTFkMDJjOWY3OGUzMjU3OWM4OA==
5
5
  data.tar.gz: !binary |-
6
- YzQxOWJiMzcxMmI3MWU3NWVkZjk3YThkNjg0NGQ5MTc5OGY5NGNmOQ==
6
+ NzNiM2JiYzA0MDczYTJiMjRkNzhmYzk3ZWVjODRhOTZiOWY3YmU5NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDA4NzI0NzY0MGNlMjNhZWUxNTBlMjNjZmYzY2I2YTkyYTFhZGEzNGQyNDQ3
10
- M2JlZDBmNjg4ZDM0Njk5MjNiZTRiMDk3OTI1ZjdmN2RlNDI4NTgxY2ZmYjY2
11
- MGQ3OWU0YTRjNmMzMmFhNzc2MDI2NzAyYmNiMGJhYjVkYTJjZTU=
9
+ M2VhZGI5MWFmYTM1OTUwODRhODRmNDc3YTA0ZThlYzk4NDcxYTQ0NzhkOTRi
10
+ ZmM4NmZlYmM4MWY5ZmRmNDNlM2YyNjA2MTUzYzljNTgxMTA4MWJhYzI5NThk
11
+ M2IxZGNhNmVkNTY2YTM2ZTlhNDhmOGY1YzA0NzhhZjM4ZDM3MTQ=
12
12
  data.tar.gz: !binary |-
13
- ZjNmYzY1ZDVmZDc5NTQwYTEwYjdlMTExMTFkNDcwMjA4YjRhZTlmMGNkMzI0
14
- ZjUyMWEzN2M1NGE1MTNkYjQ1ZTcwYTAxYzQ3NGEwNzBmNjFhNzQxNWE4MDk2
15
- YTVkNTg3ZWZmMzc4ZDVkYzMwZWNkYzA4ZjViOWU3NmZkYjk2NzQ=
13
+ ZTM3NmFmNWYxYjJlZjMzZTU4NmJlODk4OGU2MmUyOWQ3OGFmZWNhMDgzYTZl
14
+ OWNhZDUxYWMxYzNkMmM5OGUwMGM0Y2Y4YjhlNzQzZTdiNzc0NWQwZjdhMTli
15
+ MmY2YzA5ZDc4NTY5MGE2MGQ1ZTYzMWFlZjBhYmMwMzY2ODlhZTk=
data/README.md CHANGED
@@ -13,6 +13,12 @@ Submit a PR, adding a file to `sheets` folder, with the cheat-sheet name.
13
13
 
14
14
  ## Usage
15
15
 
16
+ ### List all cheat sheets
17
+
18
+ $ cheatly list
19
+
20
+ ### Show a cheat sheet
21
+
16
22
  $ cheatly show gem_release
17
23
 
18
24
  ## Contributing
@@ -22,3 +28,7 @@ Submit a PR, adding a file to `sheets` folder, with the cheat-sheet name.
22
28
  3. Commit your changes (`git commit -am 'Add some feature'`)
23
29
  4. Push to the branch (`git push origin my-new-feature`)
24
30
  5. Create new Pull Request
31
+
32
+
33
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/arthurnn/cheatly/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
34
+
@@ -0,0 +1,56 @@
1
+ module Cheatly
2
+ class Sheet
3
+ attr_accessor :title, :body
4
+ def initialize(title, body)
5
+ @title, @body = title, body
6
+ end
7
+
8
+ def to_s
9
+ " #{@body.gsub("\r",'').gsub("\n", "\n ")}"
10
+ end
11
+
12
+ def self.find(handle)
13
+ sheet_yaml = adapter.find("sheets/#{handle}.yml")
14
+ yml = YAML.load(sheet_yaml).first
15
+ t, b = yml.first, yml.last
16
+ Sheet.new(t, b)
17
+ end
18
+
19
+ def self.all
20
+ handles = adapter.all
21
+ handles.map { |h| Sheet.new(h, nil) }
22
+ end
23
+
24
+ def self.adapter
25
+ # @adapter ||= FileAdapter.new
26
+ @adapter ||= GithubAdapter.new
27
+ end
28
+ end
29
+
30
+ class FileAdapter
31
+ def find(path)
32
+ File.read(path)
33
+ end
34
+ end
35
+
36
+ class GithubAdapter
37
+ include HTTParty
38
+ base_uri 'https://api.github.com'
39
+
40
+ def base_path
41
+ "/repos/arthurnn/cheatly/contents"
42
+ end
43
+
44
+ def find(path)
45
+ response = self.class.get("#{base_path}/#{path}")
46
+ json = JSON.parse(response.body)
47
+ Base64.decode64(json["content"])
48
+ end
49
+
50
+ def all
51
+ response = self.class.get("#{base_path}/sheets")
52
+ json = JSON.parse(response.body)
53
+ json.map { |entry| entry["name"].gsub('.yml', '') }
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module Cheatly
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/cheatly.rb CHANGED
@@ -1,17 +1,24 @@
1
- require "cheatly/version"
2
1
  require "base64"
3
2
  require "json"
4
3
 
5
4
  require "httparty"
6
5
  require "pager"
7
6
 
7
+ require "cheatly/sheet"
8
+ require "cheatly/version"
9
+
8
10
  module Cheatly
9
11
  class CLI
10
12
  include Pager
11
13
 
12
14
  def initialize(args)
13
- @command = args.shift
15
+ @command = args.shift || "help"
14
16
  @handle = args.first
17
+
18
+ if "help" == @command
19
+ @handle = @command
20
+ @commands = "show"
21
+ end
15
22
  end
16
23
 
17
24
  def sheet(handle)
@@ -21,53 +28,24 @@ module Cheatly
21
28
  puts sheet.to_s
22
29
  end
23
30
 
24
- def process
25
- sheet(@handle)
26
- end
27
- end
28
-
29
- class Sheet
30
- attr_accessor :title, :body
31
- def initialize(title, body)
32
- @title, @body = title, body
33
- end
34
-
35
- def to_s
36
- " #{@body.gsub("\r",'').gsub("\n", "\n ")}"
37
- end
38
-
39
- def self.find(handle)
40
- sheet_yaml = adapter.find("sheets/#{handle}.yml")
41
- yml = YAML.load(sheet_yaml).first
42
- t, b = yml.first, yml.last
43
- Sheet.new(t, b)
44
- end
45
-
46
- def self.adapter
47
- # @adapter ||= FileAdapter.new
48
- @adapter ||= GithubAdapter.new
49
- end
50
- end
51
-
52
- class FileAdapter
53
- def find(path)
54
- File.read(path)
55
- end
56
- end
57
-
58
- class GithubAdapter
59
- include HTTParty
60
- base_uri 'https://api.github.com'
61
-
62
- def base_path
63
- "/repos/arthurnn/cheatly/contents"
31
+ def list
32
+ sheets = Sheet.all
33
+ page
34
+ puts "List of available cheat-sheets:"
35
+ sheets.each do |sheet|
36
+ puts " #{sheet.title}"
37
+ end
64
38
  end
65
39
 
66
- def find(path)
67
- response = self.class.get("#{base_path}/#{path}")
68
- json = JSON.parse(response.body)
69
- Base64.decode64(json["content"])
40
+ def process
41
+ case @command
42
+ when "show"
43
+ sheet(@handle)
44
+ when "list"
45
+ list
46
+ else
47
+ puts "Command [#{@command}] not found. :-("
48
+ end
70
49
  end
71
-
72
50
  end
73
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheatly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Neves
@@ -82,6 +82,7 @@ files:
82
82
  - bin/cheatly
83
83
  - cheatly.gemspec
84
84
  - lib/cheatly.rb
85
+ - lib/cheatly/sheet.rb
85
86
  - lib/cheatly/version.rb
86
87
  - sheets/gem_release.yml
87
88
  - sheets/strftime.yml