favt 0.0.7 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/favt +34 -10
  3. data/lib/favt.rb +49 -11
  4. data/lib/favt/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c81981dc8d029ac0c93c5bfe3cc5d11f91b7643b
4
- data.tar.gz: 7463aff362f13d49bc259f97a6ea57e334b0a034
3
+ metadata.gz: 8ea6e7884c78dc9a87a2df33da350b76f53ec657
4
+ data.tar.gz: a16bae914515ca427b9b681bbfeddc4f4850388b
5
5
  SHA512:
6
- metadata.gz: dc62484fb551c8124a43bfd3d6ae73f946bc080ef07d12f71b11c8e726c880a3da35b4a2819d9df2fbf04f59a5f86cd5386c928e3bf959352207e294df9adf8c
7
- data.tar.gz: 4f228608d1f0eb7396dbbd51ee2e18dd7a474e8e0b5064a383ffdfef5fd46b6b0bb8398b7d48734216d7e602e7747c7dced2544627adb49a8a1a1fd242cfb9a5
6
+ metadata.gz: 203442991f08bf557e022fcacd12ab0b8c281596f8c35921df5ce06e2cccaba47fc64b159a1111148c84b43b2aa98cf8769a9eeb82aa39525ede110f599d2019
7
+ data.tar.gz: 98b136059f648def0998f40d8e0cee2438415a0abca86accd9429b693e275c5a3aa0d91459f9e55eeb161f27c1df7670c6371d7fc9a38e374054c614f08f2003
data/bin/favt CHANGED
@@ -6,7 +6,7 @@ require 'favt'
6
6
  require 'twitter'
7
7
 
8
8
  def option_parse
9
- options = {}
9
+ options = {"no_color" => false}
10
10
  OptionParser.new do |opts|
11
11
 
12
12
  opts.banner = "Usage: Twitter Favorite Reader"
@@ -23,24 +23,48 @@ def option_parse
23
23
  "Set any config yaml file (default:config.yaml)") do |file|
24
24
  options["config_file"] = file
25
25
  end
26
+
27
+ opts.on("--no-color", "use coloring console") do
28
+ options["no_color"] = true
29
+ end
26
30
  end.parse!
27
31
  return options
28
32
  end
29
33
 
30
- def error_print(title)
31
- print "Error!!".light_red
32
- print " -- ".light_green
34
+ def error_print(title, options)
35
+
36
+ error_template = {
37
+ error_title: "Error!!",
38
+ error_line: " -- "
39
+ }
40
+
41
+ if !options["no_color"]
42
+ error_template[:error_title] = error_template[:error_title].red
43
+ error_template[:error_line] = error_template[:error_line].light_green
44
+ end
45
+
46
+ error_template.each_value { |value| print value}
33
47
  print title.uncolorize
34
48
  end
35
49
 
36
50
 
37
- begin
38
- ft = Favt::TwitterClient.new(option_parse)
39
- ft.render()
40
- rescue Twitter::Error::TooManyRequests => e
41
- error_print("Twitter API, Too Many Requests. Perhaps, Rate Limit Exceeded. \n")
51
+ begin
52
+
53
+ options = option_parse
54
+
55
+ ft = Favt::TwitterClient.new(options)
56
+ ft.render
57
+
58
+ rescue Twitter::Error::TooManyRequests
59
+
60
+ message = "Twitter API, Too Many Requests. Perhaps, Rate Limit Exceeded. \n"
61
+ error_print(message, options)
62
+
42
63
  rescue Errno::ENOENT
43
- error_print("Config file is not found.\n")
64
+
65
+ message = "Config file is not found.\n"
66
+ error_print(message, options)
67
+
44
68
  print <<EOF
45
69
 
46
70
  Config file examples (config.yaml)
@@ -18,7 +18,7 @@ module Favt
18
18
 
19
19
  def initialize(options)
20
20
  yaml_file = options["config_file"] || "config.yaml"
21
-
21
+ @render = options["render"] || Render
22
22
  @options = options
23
23
  @config = YAML.load_file(yaml_file)
24
24
 
@@ -27,9 +27,9 @@ module Favt
27
27
 
28
28
  def favorites_from_user
29
29
  users = self.target_users
30
- favorites = users.map do |user|
30
+ return users.flat_map do |user|
31
31
  @client.favorites user
32
- end.flatten!
32
+ end
33
33
  end
34
34
 
35
35
  def take(set_fav_posts)
@@ -70,15 +70,53 @@ module Favt
70
70
 
71
71
  def render
72
72
  self.favorite_posts.each do |_, favorite|
73
- favorite["users"].times do
74
- print "■".red
75
- end
76
-
77
- post = favorite["post"]
78
- print "[#{post.user.screen_name}] ".green.bold
79
- print "#{post.text}\n".uncolorize
80
- print "#{post.url}\n".blue
73
+ print @render.new(favorite, @options).to_s
74
+ end
75
+ end
76
+ end
77
+
78
+ class Render
79
+ def initialize(favorite, options)
80
+ @users = favorite["users"]
81
+ @post = favorite["post"]
82
+ @options = options
83
+ end
84
+
85
+ def render_users
86
+ render = "■"
87
+
88
+ if !@options["no_color"]
89
+ render = render.red
81
90
  end
91
+
92
+ @users.times do
93
+ print render
94
+ end
95
+ end
96
+
97
+ def post_colorize(render_dict)
98
+ if !@options["no_color"]
99
+ render_dict[:screen_name] = render_dict[:screen_name].green.bold
100
+ render_dict[:post_url] = render_dict[:post_url].blue
101
+ end
102
+ return render_dict
103
+ end
104
+
105
+ def render_post
106
+ post = @post
107
+
108
+ post_template = {
109
+ screen_name: "[#{post.user.screen_name}] ",
110
+ post_text: "#{post.text}\n",
111
+ post_url: "#{post.url}\n",
112
+ }
113
+
114
+ self.post_colorize(post_template).values.join
115
+ end
116
+
117
+ def to_s
118
+ self.render_users
119
+ self.render_post
82
120
  end
83
121
  end
84
122
  end
@@ -1,3 +1,3 @@
1
1
  module Favt
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - esehara shigeo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-04 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter